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
display Products assigned to the Current Store on the PLP
Łukasz Adamczyk005e8e21361a
diff --git a/core/lib/spree/core/search/base.rb b/core/lib/spree/core/search/base.rbindex 7ba985df8b..5a358a44ab 100644--- a/core/lib/spree/core/search/base.rb+++ b/core/lib/spree/core/search/base.rb@@ -28,6 +28,7 @@ module Spreedef extended_base_scopebase_scope = Spree::Product.spree_base_scopes+ base_scope = base_scope.by_store(current_store) if current_store.present?base_scope = get_products_conditions_for(base_scope, keywords)base_scope = Spree::Dependencies.products_finder.constantize.new(scope: base_scope,@@ -114,6 +115,7 @@ module Spreeenddef prepare(params)+ @properties[:current_store] = Spree::Store.find_by(id: params[:current_store_id])@properties[:taxon] = params[:taxon].blank? ? nil : Spree::Taxon.find(params[:taxon])@properties[:keywords] = params[:keywords]@properties[:option_value_ids] = build_option_value_ids(params)diff --git a/core/spec/lib/search/base_spec.rb b/core/spec/lib/search/base_spec.rbindex 427bb2f2c0..5bf1eb0968 100644--- a/core/spec/lib/search/base_spec.rb+++ b/core/spec/lib/search/base_spec.rb@@ -93,4 +93,85 @@ describe Spree::Core::Search::Base dosearcher.current_currency = 'EUR'expect(searcher.retrieve_products).to eq([product1])end++ describe 'searching by a current store' do+ subject(:retrieved_products) { searcher.retrieve_products }++ let(:searcher) { described_class.new(params) }++ let(:eu_store) { create(:store, name: 'EU Store', default_currency: 'EUR') }+ let(:uk_store) { create(:store, name: 'UK Store', default_currency: 'GBP') }+ let(:spree_store) { create(:store, name: 'Spree Demo Site', default_currency: 'USD', default: true) }++ let!(:products_for_eu_store) do+ (1..3).map do |v|+ create(:product, name: "P-EU-#{v}", stores: [eu_store])+ end+ end++ let!(:products_for_uk_store) do+ (1..2).map do |v|+ create(:product, name: "P-UK-#{v}", stores: [uk_store])+ end+ end++ let!(:product_for_spree_store) { create(:product, name: 'P-Spree-1', stores: [spree_store]) }++ context 'current_store_id is given in params' do+ let(:params) { { current_store_id: current_store.id } }++ context 'when EU Store' do+ let(:current_store) { eu_store }++ it 'returns 3 products' do+ expect(retrieved_products.count).to eq(3)+ end++ it 'returns only products from EU store' do+ expect(retrieved_products).to contain_exactly(*products_for_eu_store)+ end+ end++ context 'when UK Store' do+ let(:current_store) { uk_store }++ it 'returns 2 products' do+ expect(retrieved_products.count).to eq(2)+ end++ it 'returns only products from UK store' do+ expect(retrieved_products).to contain_exactly(*products_for_uk_store)+ end+ end++ context 'when Spree Store' do+ let(:current_store) { spree_store }++ it 'returns 1 product' do+ expect(retrieved_products.count).to eq(1)+ end++ it 'returns only products from Spree store' do+ expect(retrieved_products).to contain_exactly(product_for_spree_store)+ end+ end+ end++ context 'store id is not given in params' do+ let(:params) { { current_store_id: nil } }++ it 'returns 8 products' do+ expect(retrieved_products.count).to eq(8)+ end++ it 'returns products from all stores' do+ expect(retrieved_products).to contain_exactly(+ product1, product2,+ product_for_spree_store,+ *products_for_eu_store,+ *products_for_uk_store+ )+ end+ end+ endenddiff --git a/frontend/app/controllers/spree/taxons_controller.rb b/frontend/app/controllers/spree/taxons_controller.rbindex 7b668ace06..b98c3b391b 100644--- a/frontend/app/controllers/spree/taxons_controller.rb+++ b/frontend/app/controllers/spree/taxons_controller.rb@@ -36,7 +36,13 @@ module Spreeenddef load_products- @searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))+ search_params = params.merge(+ current_store_id: current_store.id,+ taxon: @taxon.id,+ include_images: true+ )++ @searcher = build_searcher(search_params)@products = @searcher.retrieve_productsend