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 `StoreController#storefront_product_finder` method (#13025)

Damian Legawiec773811fcfb99
diff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rb
index ba2f591364..e9ddd2de97 100644
--- a/storefront/app/controllers/spree/store_controller.rb
+++ b/storefront/app/controllers/spree/store_controller.rb
@@ -29,7 +29,7 @@ module Spree
helper_method :permitted_products_params, :products_filters_params,
:storefront_products_scope, :storefront_products,
:default_products_sort, :default_products_finder_params,
- :storefront_products_includes
+ :storefront_products_includes, :storefront_products_finder
helper_method :stored_location
@@ -123,6 +123,10 @@ module Spree
@accurate_title ||= current_store.seo_title.presence || current_store.name
end
+ def storefront_products_finder
+ @storefront_products_finder ||= Spree::Dependencies.products_finder.constantize
+ end
+
def storefront_products_scope
@storefront_products_scope ||= current_store.products.active(current_currency)
end
@@ -156,7 +160,7 @@ module Spree
finder_params = default_products_finder_params
finder_params[:sort_by] ||= @taxon&.sort_order || 'manual'
- products_finder = Spree::Dependencies.products_finder.constantize
+ products_finder = storefront_products_finder
products = products_finder.
new(scope: storefront_products_scope, params: finder_params).
execute.
diff --git a/storefront/app/helpers/spree/filters_helper.rb b/storefront/app/helpers/spree/filters_helper.rb
index 2021c72325..41f5581bde 100644
--- a/storefront/app/helpers/spree/filters_helper.rb
+++ b/storefront/app/helpers/spree/filters_helper.rb
@@ -8,12 +8,10 @@ module Spree
end
def products_for_filters_scope(except_filters: [])
- products_finder = Spree::Dependencies.products_finder.constantize
-
finder_params = default_products_finder_params
finder_params[:filter] = finder_params[:filter].except(*except_filters) if except_filters.any?
- products = products_finder.new(scope: storefront_products_scope, params: finder_params).execute
+ products = storefront_products_finder.new(scope: storefront_products_scope, params: finder_params).execute
current_store.products.where(id: products.unscope(:order).ids)
end
diff --git a/storefront/app/helpers/spree/taxons_helper.rb b/storefront/app/helpers/spree/taxons_helper.rb
index 1f5f7752ad..2d9139d348 100644
--- a/storefront/app/helpers/spree/taxons_helper.rb
+++ b/storefront/app/helpers/spree/taxons_helper.rb
@@ -12,8 +12,7 @@ module Spree
sort_by: 'default'
}
- products_finder = Spree::Dependencies.products_finder.constantize
- products_finder.new(scope: current_store.products.includes(storefront_products_includes), params: finder_params).execute
+ storefront_products_finder.new(scope: current_store.products.includes(storefront_products_includes), params: finder_params).execute
end
end
end