Module: Gemgento::CategoriesHelper

Defined in:
app/helpers/gemgento/categories_helper.rb

Instance Method Summary collapse

Instance Method Details

#cache_keyArray

Cache key values for categories#show fragment cache.

Returns:

  • (Array)


23
24
25
26
27
28
29
30
# File 'app/helpers/gemgento/categories_helper.rb', line 23

def cache_key
  cache_key = [@current_category]
  cache_key << user_signed_in? ? current_user.user_group : nil
  cache_key << @products.maximum(:cache_expires_at) if @products
  cache_key += query_params_cache_keys

  return cache_key
end

#filter_options(attribute) ⇒ Array(String)

Get a list of values for a given attribute. Values are based on all filters except the filter for the given attribute.

Parameters:

  • attribute (Symbol)

    Gemgento::Attribute code

Returns:

  • (Array(String))


8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/gemgento/categories_helper.rb', line 8

def filter_options(attribute)
  filters = @filters.select{ |f| (f[:attribute].is_a?(Array) ? f[:attribute].first[:code] : f[:attribute].code) != attribute.to_s }

  products = Gemgento::Product.active.catalog_visible
                 .joins(:product_categories)
                 .where('gemgento_product_categories.category_id = ?', @current_category.id)
  products = products.filter(filters) if filters.any?

  options = products.map(&attribute)
  options.uniq.reject(&:blank?).sort
end

#query_params_cache_keysArray(String)

Cache key values from query string.

Returns:

  • (Array(String))


35
36
37
# File 'app/helpers/gemgento/categories_helper.rb', line 35

def query_params_cache_keys
  [params[:page]]
end