Sha256: adc2e53c57cd3ff3d3c24a435f928aa1dc0143dbad24cf496bfdb21c55b12a4d

Contents?: true

Size: 771 Bytes

Versions: 6

Compression:

Stored size: 771 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.limit(max)
      if (products.size < max)
        taxon.descendants.each do |taxon|
          to_get = max - products.length
          products += taxon.active_products.limit(to_get)
          products = products.uniq
          break if products.size >= max
        end
      end
      products
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-2.1.5 app/helpers/spree/taxons_helper.rb
spree_core-2.1.4 app/helpers/spree/taxons_helper.rb
spree_core-2.1.3 app/helpers/spree/taxons_helper.rb
spree_core-2.1.2 app/helpers/spree/taxons_helper.rb
spree_core-2.1.1 app/helpers/spree/taxons_helper.rb
spree_core-2.1.0 app/helpers/spree/taxons_helper.rb