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
refactor Products Searcher
Łukasz Adamczyk776b1f4b6ecf
diff --git a/core/lib/spree/core/search/base.rb b/core/lib/spree/core/search/base.rbindex 5a358a44ab..568f9a94e1 100644--- a/core/lib/spree/core/search/base.rb+++ b/core/lib/spree/core/search/base.rb@@ -2,13 +2,14 @@ module Spreemodule Coremodule Searchclass Base- attr_accessor :properties- attr_accessor :current_user- attr_accessor :current_currency+ attr_accessor :properties, :current_user, :current_currency, :current_store, :taxondef initialize(params)- self.current_currency = Spree::Config[:currency]@properties = {}+ @current_currency = Spree::Config[:currency]+ @current_store = params[:current_store]+ @taxon = params[:taxon]+prepare(params)end@@ -115,8 +116,6 @@ 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)@properties[:price] = get_price_range(params[:price])diff --git a/core/spec/lib/search/base_spec.rb b/core/spec/lib/search/base_spec.rbindex 5bf1eb0968..fc5ad6165e 100644--- a/core/spec/lib/search/base_spec.rb+++ b/core/spec/lib/search/base_spec.rb@@ -21,7 +21,7 @@ describe Spree::Core::Search::Base docontext 'when include_images is included in the initalization params' dosubject { described_class.new(params).retrieve_products }- let(:params) { { include_images: true, keyword: product1.name, taxon: taxon.id } }+ let(:params) { { include_images: true, keyword: product1.name, taxon: taxon } }before doproduct1.master.images << create(:image, position: 2)@@ -117,8 +117,8 @@ describe Spree::Core::Search::Base dolet!(: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 'current sture is given in params' do+ let(:params) { { current_store: current_store } }context 'when EU Store' dolet(:current_store) { eu_store }@@ -157,8 +157,8 @@ describe Spree::Core::Search::Base doendend- context 'store id is not given in params' do- let(:params) { { current_store_id: nil } }+ context 'current store is not given in params' do+ let(:params) { { current_store: nil } }it 'returns 8 products' doexpect(retrieved_products.count).to eq(8)diff --git a/frontend/app/controllers/spree/products_controller.rb b/frontend/app/controllers/spree/products_controller.rbindex 7bdd8f60db..183762a2aa 100644--- a/frontend/app/controllers/spree/products_controller.rb+++ b/frontend/app/controllers/spree/products_controller.rb@@ -12,7 +12,7 @@ module Spreerespond_to :htmldef index- @searcher = build_searcher(params.merge(include_images: true, current_store_id: current_store.id))+ @searcher = build_searcher(params.merge(include_images: true, current_store: current_store))@products = @searcher.retrieve_productsif http_cache_enabled?diff --git a/frontend/app/controllers/spree/taxons_controller.rb b/frontend/app/controllers/spree/taxons_controller.rbindex b98c3b391b..37251482fc 100644--- a/frontend/app/controllers/spree/taxons_controller.rb+++ b/frontend/app/controllers/spree/taxons_controller.rb@@ -37,8 +37,8 @@ module Spreedef load_productssearch_params = params.merge(- current_store_id: current_store.id,- taxon: @taxon.id,+ current_store: current_store,+ taxon: @taxon,include_images: true)