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
Add products scope to FeaturedTaxon (#13009)
brozeke735c1c38494
diff --git a/core/app/models/spree/page_sections/featured_taxon.rb b/core/app/models/spree/page_sections/featured_taxon.rbindex 8f4e69f6ed..4b70f335ce 100644--- a/core/app/models/spree/page_sections/featured_taxon.rb+++ b/core/app/models/spree/page_sections/featured_taxon.rb@@ -50,6 +50,11 @@ module Spreeenddef products(currency)+ Spree::Deprecation.warn(+ 'FeaturedTaxon#products is deprecated and will be removed in Spree 6.0. ' \+ 'Please use taxon_products(featured_taxon.taxon) helper method in views instead'+ )+@products ||= beginfinder_params = {store: store,diff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rbindex 042c6b39a1..ba2f591364 100644--- a/storefront/app/controllers/spree/store_controller.rb+++ b/storefront/app/controllers/spree/store_controller.rb@@ -28,7 +28,8 @@ module Spreehelper_method :permitted_products_params, :products_filters_params,:storefront_products_scope, :storefront_products,- :default_products_sort, :default_products_finder_params+ :default_products_sort, :default_products_finder_params,+ :storefront_products_includeshelper_method :stored_locationdiff --git a/storefront/app/helpers/spree/taxons_helper.rb b/storefront/app/helpers/spree/taxons_helper.rbnew file mode 100644index 0000000000..1f5f7752ad--- /dev/null+++ b/storefront/app/helpers/spree/taxons_helper.rb@@ -0,0 +1,20 @@+module Spree+ module TaxonsHelper+ # @param taxon [Spree::Taxon]+ # @return [ActiveRecord::Relation<Spree::Product>] products for the taxon+ def taxon_products(taxon)+ @products_cache ||= {}+ @products_cache[taxon.id] ||= begin+ finder_params = {+ store: current_store,+ filter: { taxons: taxon.id },+ currency: current_currency,+ 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+ end+ end+ end+enddiff --git a/storefront/app/views/themes/default/spree/page_sections/_featured_taxon.html.erb b/storefront/app/views/themes/default/spree/page_sections/_featured_taxon.html.erbindex 2f322a1628..c97454b2d1 100644--- a/storefront/app/views/themes/default/spree/page_sections/_featured_taxon.html.erb+++ b/storefront/app/views/themes/default/spree/page_sections/_featured_taxon.html.erb@@ -42,7 +42,8 @@</div><% end %><% if loaded && section.taxon.present? %>- <% if section.products(current_currency).any? %>+ <% taxon_products = taxon_products(section.taxon).limit(section.preferred_max_products_to_show) %>+ <% if taxon_products.any? %><div class='grid grid-cols-1 lg:grid-cols-12 gap-4 lg:gap-6'><% if section_with_image %><div class='lg:col-span-5'>@@ -52,7 +53,7 @@</div><% end %><div class='<%= section_with_image ? "lg:col-span-7" : "lg:col-span-12" %>'>- <%= render 'spree/products/swiper', products: section.products(current_currency).first(section.preferred_max_products_to_show), desktop_slides: desktop_slides_amount, pagination: 'bottom', arrows_on_top: arrows_on_top, section: section %>+ <%= render 'spree/products/swiper', products: taxon_products, desktop_slides: desktop_slides_amount, pagination: 'bottom', arrows_on_top: arrows_on_top, section: section %></div></div><% end %>