Sha256: ea299db24ba24bcad39a7aa936b169fecd5131e296dfb74b806b693a710776a3

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Harpiya
  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)
      ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
        TaxonsHelper is deprecated and will be removed in Harpiya 5.0.
        Please remove any `helper 'harpiya/taxons'` from your controllers.
      DEPRECATION
      products = taxon.active_products.distinct.select('harpiya_products.*, harpiya_products_taxons.position').limit(max)
      if products.size < max
        products_arel = Harpiya::Product.arel_table
        taxon.descendants.each do |child|
          to_get = max - products.length
          products += child.active_products.distinct.select('harpiya_products.*, harpiya_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

1 entries across 1 versions & 1 rubygems

Version Path
harpiya_frontend-4.3.0.alpha app/helpers/harpiya/taxons_helper.rb