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
Added `disable_store_presence_validation` preference option
Damian Legawiecd9bd5f52a2fc
diff --git a/core/app/models/concerns/spree/multiple_stores_resource.rb b/core/app/models/concerns/spree/multiple_stores_resource.rbindex f840b7e7c9..d61a5ee172 100644--- a/core/app/models/concerns/spree/multiple_stores_resource.rb+++ b/core/app/models/concerns/spree/multiple_stores_resource.rb@@ -18,7 +18,7 @@ module Spree# this can be overriden on model basisdef disable_store_presence_validation?- false+ Spree::Config[:disable_store_presence_validation]endendenddiff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rbindex 7458061611..d663a64c76 100644--- a/core/app/models/spree/app_configuration.rb+++ b/core/app/models/spree/app_configuration.rb@@ -45,6 +45,7 @@ module Spreepreference :currency, :string, default: 'USD'preference :default_country_id, :integerpreference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validation+ preference :disable_store_presence_validation, :boolean, default: false # when turned off disables Store presence validation for Products and Payment Methodspreference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being chargedpreference :layout, :string, default: 'spree/layouts/spree_application'diff --git a/core/spec/models/spree/payment_method_spec.rb b/core/spec/models/spree/payment_method_spec.rbindex 7cba681137..ec38a1b060 100644--- a/core/spec/models/spree/payment_method_spec.rb+++ b/core/spec/models/spree/payment_method_spec.rb@@ -140,10 +140,26 @@ describe Spree::PaymentMethod, type: :model doenddescribe '#ensure_store_presence' do- let(:valid_payment_method) { build(:payment_method, stores: [create(:store)]) }- let(:invalid_payment_mthod) { build(:payment_method, stores: []) }+ let(:valid_record) { build(:payment_method, stores: [create(:store)]) }+ let(:invalid_record) { build(:payment_method, stores: []) }- it { expect(valid_payment_method).to be_valid }- it { expect(invalid_payment_mthod).not_to be_valid }+ it { expect(valid_record).to be_valid }+ it { expect(invalid_record).not_to be_valid }++ context 'validation disabled' do+ context 'method overwrite' do+ before { allow_any_instance_of(described_class).to receive(:disable_store_presence_validation?).and_return(true) }++ it { expect(valid_record).to be_valid }+ it { expect(invalid_record).to be_valid }+ end++ context 'preference set' do+ before { Spree::Config[:disable_store_presence_validation] = true }++ it { expect(valid_record).to be_valid }+ it { expect(invalid_record).to be_valid }+ end+ endendenddiff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rbindex 8bb8f45854..cc958752e0 100644--- a/core/spec/models/spree/product_spec.rb+++ b/core/spec/models/spree/product_spec.rb@@ -761,10 +761,26 @@ describe Spree::Product, type: :model doenddescribe '#ensure_store_presence' do- let(:valid_product) { build(:product, stores: [create(:store)]) }- let(:invalid_product) { build(:product, stores: []) }+ let(:valid_record) { build(:product, stores: [create(:store)]) }+ let(:invalid_record) { build(:product, stores: []) }- it { expect(valid_product).to be_valid }- it { expect(invalid_product).not_to be_valid }+ it { expect(valid_record).to be_valid }+ it { expect(invalid_record).not_to be_valid }++ context 'validation disabled' do+ context 'method overwrite' do+ before { allow_any_instance_of(described_class).to receive(:disable_store_presence_validation?).and_return(true) }++ it { expect(valid_record).to be_valid }+ it { expect(invalid_record).to be_valid }+ end++ context 'preference set' do+ before { Spree::Config[:disable_store_presence_validation] = true }++ it { expect(valid_record).to be_valid }+ it { expect(invalid_record).to be_valid }+ end+ endendend