Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added `ShippingRate#delivery_range` and `ShippingRate#display_delivery_range`

Damian Legawiec39e429283521
diff --git a/core/app/models/spree/shipping_rate.rb b/core/app/models/spree/shipping_rate.rb
index 3eabd3df76..62fd3242cf 100644
--- a/core/app/models/spree/shipping_rate.rb
+++ b/core/app/models/spree/shipping_rate.rb
@@ -41,6 +41,24 @@ module Spree
end
end
+ # Returns the delivery range for the shipping method
+ #
+ # @return [String]
+ def delivery_range
+ return unless shipping_method.delivery_range
+
+ shipping_method.delivery_range
+ end
+
+ # Returns the display delivery range for the shipping method
+ #
+ # @return [String]
+ def display_delivery_range
+ return unless delivery_range
+
+ Spree.t(:display_delivery_range, delivery_range: delivery_range)
+ end
+
private
def discount_amount
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index fdb5ddc89c..ba1adefef1 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -812,6 +812,7 @@ en:
discontinued: Discontinued
dismiss_banner: No. Thanks! I'm not interested, do not display this message again
display: Display
+ display_delivery_range: "Delivery in %{delivery_range} business days"
doesnt_track_inventory: It doesn't track inventory
dont_have_account: No account?
draft_mode: Draft Mode
diff --git a/core/spec/models/spree/shipping_rate_spec.rb b/core/spec/models/spree/shipping_rate_spec.rb
index 3f868486f7..7abbf7a69c 100644
--- a/core/spec/models/spree/shipping_rate_spec.rb
+++ b/core/spec/models/spree/shipping_rate_spec.rb
@@ -182,4 +182,20 @@ describe Spree::ShippingRate, type: :model do
expect(shipping_rate.final_price).to eq(10.0)
end
end
+
+ describe '#delivery_range' do
+ let(:shipping_method) { create(:shipping_method, estimated_transit_business_days_min: 1, estimated_transit_business_days_max: 2) }
+
+ it 'returns the delivery range for the shipping method' do
+ expect(shipping_rate.delivery_range).to eq('1-2')
+ end
+ end
+
+ describe '#display_delivery_range' do
+ let(:shipping_method) { create(:shipping_method, estimated_transit_business_days_min: 1, estimated_transit_business_days_max: 2) }
+
+ it 'returns the display delivery range for the shipping method' do
+ expect(shipping_rate.display_delivery_range).to eq('Delivery in 1-2 business days')
+ end
+ end
end