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
V-3066 FIX filtering storefront products with AND instead of OR (#12631)
brozeka9d44c17e303
diff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rbindex a3e2d32d68..ab9e3396d6 100644--- a/storefront/app/controllers/spree/store_controller.rb+++ b/storefront/app/controllers/spree/store_controller.rb@@ -126,6 +126,7 @@ module Spreefilter[:taxon_ids] ||= [taxon&.id.to_s].compactfilter[:taxons] = filter[:taxon_ids].join(',')+ filter[:concat_taxons] = filter[:taxons] if filter[:taxon_ids].size > 1if filter.key?(:min_price) || filter.key?(:max_price)min_price = filter[:min_price].presence || 0diff --git a/storefront/spec/controllers/spree/products_controller_spec.rb b/storefront/spec/controllers/spree/products_controller_spec.rbindex f95553e005..c572196c13 100644--- a/storefront/spec/controllers/spree/products_controller_spec.rb+++ b/storefront/spec/controllers/spree/products_controller_spec.rb@@ -16,6 +16,53 @@ describe Spree::ProductsController, type: :controller doexpect(response).to render_template(:index)expect(assigns(:current_page)).to be_a(Spree::Pages::ShopAll)end++ context 'when filtering' do+ let(:taxon) { create(:taxon) }++ context 'by one taxon' do+ let(:product) { create(:product, stores: [store], taxons: [taxon]) }++ before do+ product+ get :index, params: { filter: { taxon_ids: [taxon.id] } }+ end++ it 'returns one product' do+ expect(assigns(:storefront_products).records).to eq([product])+ end+ end++ context 'by multiple taxons' do+ let(:taxon2) { create(:taxon) }++ context 'and product is associated with both taxons' do+ let(:product) { create(:product, stores: [store], taxons: [taxon, taxon2]) }++ before do+ product+ get :index, params: { filter: { taxon_ids: [taxon.id, taxon2.id] } }+ end++ it 'returns the product' do+ expect(assigns(:storefront_products).records).to eq([product])+ end+ end++ context 'and product is associated with only one of the taxons' do+ let(:product) { create(:product, stores: [store], taxons: [taxon]) }++ before do+ product+ get :index, params: { filter: { taxon_ids: [taxon.id, taxon2.id] } }+ end++ it 'does not return the product' do+ expect(assigns(:storefront_products).records).to be_empty+ end+ end+ end+ endenddescribe '#show' do