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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Use default flag instead of code to resolve store's default channel (#14221)
Damian Legawiec478161ec372f
diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rbindex 4c118ca5c0..a17f118e69 100644--- a/spree/core/app/models/spree/store.rb+++ b/spree/core/app/models/spree/store.rb@@ -186,8 +186,13 @@ module SpreeSpree::Store.default&.supported_locales_list || []end+ # Resolves the store's default channel via the +default+ boolean column+ # so promoting another channel in the admin takes effect immediately.+ # Falls back to the first active channel only for malformed data with no+ # flagged default.+ # @return [Spree::Channel, nil]def default_channel- channels.find_by(code: Spree::Channel::DEFAULT_CODE) || channels.active.first+ channels.default.first || channels.active.firstend# @deprecated Use Markets instead. Will be removed in Spree 5.5.diff --git a/spree/core/spec/models/spree/store_spec.rb b/spree/core/spec/models/spree/store_spec.rbindex 1e81d05e20..1753bc6529 100644--- a/spree/core/spec/models/spree/store_spec.rb+++ b/spree/core/spec/models/spree/store_spec.rb@@ -201,10 +201,21 @@ describe Spree::Store, type: :model, without_global_store: true doexpect(store.default_channel.code).to eq('online')end- it 'falls back to first active channel when no online channel exists' do+ it 'follows the default flag, not the code, when another channel is promoted' do+ pos = create(:channel, store: store, name: 'POS', code: 'pos', default: true)+ expect(store.default_channel).to eq(pos)+ expect(store.channels.find_by(code: 'online')).not_to be_default+ end++ it 'still resolves the default channel after the online channel is renamed' dostore.channels.find_by(code: 'online').update!(code: 'web')expect(store.default_channel.code).to eq('web')end++ it 'falls back to the first active channel when no channel is flagged default' do+ store.channels.update_all(default: false)+ expect(store.default_channel).to eq(store.channels.active.first)+ endendend