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
Rename Product#by_store to Product#for_store
Damian Legawiecffb3d292df36
diff --git a/api/app/controllers/spree/api/v2/resource_controller.rb b/api/app/controllers/spree/api/v2/resource_controller.rbindex dbc8f80d2c..39b24e7c21 100644--- a/api/app/controllers/spree/api/v2/resource_controller.rb+++ b/api/app/controllers/spree/api/v2/resource_controller.rb@@ -27,15 +27,17 @@ module Spreeenddef scope- base_scope = if model_class.respond_to?(:store_id)- model_class.where(store_id: current_store.id)- elsif model_class.respond_to?(:for_store)- model_class.for_store(current_store)+ plural_model_name = model_class.model_name.plural.gsub(/spree_/, '').to_sym++ base_scope = if current_store.respond_to?(plural_model_name)+ current_store.send(plural_model_name)elsemodel_classend- base_scope.accessible_by(current_ability, :show).includes(scope_includes)+ base_scope = base_scope.accessible_by(current_ability, :show)+ base_scope = base_scope.includes(scope_includes) if scope_includes.any?+ base_scopeenddef scope_includesdiff --git a/core/app/models/concerns/spree/product_scopes.rb b/core/app/models/concerns/spree/product_scopes.rbindex 048d2b9535..ca4672d2a6 100644--- a/core/app/models/concerns/spree/product_scopes.rb+++ b/core/app/models/concerns/spree/product_scopes.rb@@ -62,10 +62,6 @@ module Spreewhere("#{price_table_name}.amount >= ?", price)end- add_search_scope :by_store do |store|- joins(:stores).where(Spree::StoreProduct.table_name => { store_id: store.id })- end-# This scope selects products in taxon AND all its descendants# If you need products only within one taxon use#@@ -250,10 +246,9 @@ module Spreeendsearch_scopes << :active- def self.for_filters(currency, taxon: nil, store: nil)+ def self.for_filters(currency, taxon: nil)scope = active(currency)scope = scope.in_taxon(taxon) if taxon.present?- scope = scope.by_store(store) if store.present?scopeendsearch_scopes << :for_filtersdiff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rbindex 40b01e8616..356f2e51c8 100644--- a/core/app/models/spree/product.rb+++ b/core/app/models/spree/product.rb@@ -21,7 +21,8 @@module Spreeclass Product < Spree::Baseextend FriendlyId- include Spree::ProductScopes+ include ProductScopes+ include MultipleStoresResourcefriendly_id :slug_candidates, use: :historydiff --git a/core/lib/spree/testing_support/factories/product_factory.rb b/core/lib/spree/testing_support/factories/product_factory.rbindex 6860ea8238..397e9f81ee 100644--- a/core/lib/spree/testing_support/factories/product_factory.rb+++ b/core/lib/spree/testing_support/factories/product_factory.rb@@ -19,7 +19,7 @@ FactoryBot.define dobefore(:create) do |product, evaluator|if evaluator.with_store && product.stores.empty?default_store = Spree::Store.default.persisted? ? Spree::Store.default : nil- store = default_store || create(:store)+ store = default_store || create(:store, default: true)product.stores << storeenddiff --git a/core/spec/models/spree/product/scopes_spec.rb b/core/spec/models/spree/product/scopes_spec.rbindex 4e4ab96dfe..deeb0667c9 100644--- a/core/spec/models/spree/product/scopes_spec.rb+++ b/core/spec/models/spree/product/scopes_spec.rb@@ -43,11 +43,8 @@ describe 'Product scopes', type: :model dolet(:taxon_1) { create(:taxon) }let(:taxon_2) { create(:taxon) }- let(:store_1) { create(:store) }- let(:store_2) { create(:store) }-- let!(:product_1) { create(:product, currency: 'GBP', taxons: [taxon_1], stores: [store_1]) }- let!(:product_2) { create(:product, currency: 'GBP', taxons: [taxon_2], stores: [store_2]) }+ let!(:product_1) { create(:product, currency: 'GBP', taxons: [taxon_1]) }+ let!(:product_2) { create(:product, currency: 'GBP', taxons: [taxon_2]) }before docreate(:product, currency: 'USD', taxons: [create(:taxon)])@@ -57,18 +54,6 @@ describe 'Product scopes', type: :model doit { expect(subject.call('GBP', taxon: taxon_1)).to contain_exactly(product_1) }end- context 'when giving a store' do- it { expect(subject.call('GBP', store: store_2)).to contain_exactly(product_2) }- end-- context 'when giving both taxon and store' do- it { expect(subject.call('GBP', taxon: taxon_1, store: store_1)).to contain_exactly(product_1) }- end-- context 'when giving no taxon and store' do- it { expect(subject.call('GBP')).to contain_exactly(product_1, product_2) }- end-context 'when giving a currency with no products' doit { expect(subject.call('PLN')).to be_empty }end@@ -321,8 +306,8 @@ describe 'Product scopes', type: :model doendend- context '#by_store' do- subject(:products_by_store) { Spree::Product.by_store(store) }+ describe '#for_store' do+ subject(:products_by_store) { Spree::Product.for_store(store) }let(:store) { create(:store) }diff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rbindex 5c22621364..450eec4956 100644--- a/frontend/app/helpers/spree/frontend_helper.rb+++ b/frontend/app/helpers/spree/frontend_helper.rb@@ -384,7 +384,7 @@ module Spreeenddef products_for_filters- Product.for_filters(current_currency, taxon: @taxon, store: current_store)+ @products_for_filters ||= current_store.products.for_filters(current_currency, taxon: @taxon)enddef products_for_filters_cache_key