Module: Spree::TaxonsHelper
- Defined in:
- app/helpers/spree/taxons_helper.rb
Instance Method Summary collapse
-
#taxon_preview(taxon, max = 4) ⇒ Object
Retrieves the collection of products to display when “previewing” a taxon.
Instance Method Details
#taxon_preview(taxon, max = 4) ⇒ Object
Retrieves the collection of products to display when “previewing” a taxon. This is abstracted into a helper so that we can use configurations as well as make it easier for end users to override this determination. One idea is to show the most popular products for a particular taxon (that is an exercise left to the developer.)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/spree/taxons_helper.rb', line 6 def taxon_preview(taxon, max = 4) Spree::Deprecation.warn(" TaxonsHelper is deprecated and will be removed in Spree 5.0.\n Please remove any `helper 'spree/taxons'` from your controllers.\n DEPRECATION\n products = taxon.active_products.distinct.select('spree_products.*, spree_products_taxons.position').limit(max)\n if products.size < max\n products_arel = Spree::Product.arel_table\n taxon.descendants.each do |child|\n to_get = max - products.length\n products += child.active_products.distinct.select('spree_products.*, spree_products_taxons.position').where(products_arel[:id].not_in(products.map(&:id))).limit(to_get)\n break if products.size >= max\n end\n end\n products\nend\n", caller) |