Sha256: d7602e0c85060f6648ae0e473b532313ef6def0bc37c45562fca6d7ab9c61780
Contents?: true
Size: 1017 Bytes
Versions: 96
Compression:
Stored size: 1017 Bytes
Contents
module Spree module TaxonsHelper # 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.) def taxon_preview(taxon, max=4) products = taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").limit(max) if (products.size < max) products_arel = Spree::Product.arel_table taxon.descendants.each do |taxon| to_get = max - products.length products += taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").where(products_arel[:id].not_in(products.map(&:id))).limit(to_get) break if products.size >= max end end products end end end
Version data entries
96 entries across 96 versions & 3 rubygems