Sha256: e8a2a96f8295c2ef4270d29525a3afa4dae92924c6a679d98911266c7483c3fe

Contents?: true

Size: 1.19 KB

Versions: 24

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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)
      price_scope = Spree::Price.where(current_pricing_options.search_arguments)
      products = taxon.active_products.joins(:prices).merge(price_scope).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 |descendent_taxon|
          to_get = max - products.length
          products += descendent_taxon.active_products.joins(:prices).merge(price_scope).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

24 entries across 24 versions & 2 rubygems

Version Path
solidus_core-2.8.2 app/helpers/spree/taxons_helper.rb
solidus_core-2.8.1 app/helpers/spree/taxons_helper.rb
solidus_core-2.6.3 app/helpers/spree/taxons_helper.rb
solidus_core-2.8.0 app/helpers/spree/taxons_helper.rb
solidus_core-2.7.1 app/helpers/spree/taxons_helper.rb
solidus_core-2.6.2 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.3 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.1 app/helpers/spree/taxons_helper.rb
solidus_core_devise_token_auth-2.8.0.alpha.0 app/helpers/spree/taxons_helper.rb