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 `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.rb
index 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 basis
def disable_store_presence_validation?
- false
+ Spree::Config[:disable_store_presence_validation]
end
end
end
diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb
index 7458061611..d663a64c76 100644
--- a/core/app/models/spree/app_configuration.rb
+++ b/core/app/models/spree/app_configuration.rb
@@ -45,6 +45,7 @@ module Spree
preference :currency, :string, default: 'USD'
preference :default_country_id, :integer
preference :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 Methods
preference :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 charged
preference :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.rb
index 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 do
end
describe '#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
+ end
end
end
diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb
index 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 do
end
describe '#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
+ end
end
end