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.

Use zone from Store checkout_zone_id attr

Przemek Kosakowskibc09f75cf493
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 181f99e234..e8adb2ffed 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -1,7 +1,7 @@
module Spree
module BaseHelper
def available_countries
- checkout_zone = Spree::Zone.find_by(name: Spree::Config[:checkout_zone])
+ checkout_zone = current_store.zone || Spree::Zone.find_by(name: Spree::Config[:checkout_zone])
countries = if checkout_zone && checkout_zone.kind == 'country'
checkout_zone.country_list
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index c32d304d94..a0f04769f9 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -12,9 +12,24 @@ describe Spree::BaseHelper, type: :helper do
create_list(:country, 3)
end
+ context 'with checkout zone assigned to the store' do
+ before do
+ Spree::Config[:checkout_zone] = nil
+ @zone = create(:zone, name: 'No Limits')
+ @zone.members.create(zoneable: country)
+ current_store.update(checkout_zone_id: @zone.id)
+ end
+
+ it 'return only the countries defined by the checkout_zone_id' do
+ expect(available_countries).to eq([country])
+ expect(current_store.checkout_zone_id).to eq @zone.id
+ end
+ end
+
context 'with no checkout zone defined' do
before do
Spree::Config[:checkout_zone] = nil
+ current_store.update(checkout_zone_id: nil)
end
it 'return complete list of countries' do