Module: Workarea::Admin::ProductRulesHelper

Defined in:
app/helpers/workarea/admin/product_rules_helper.rb

Instance Method Summary collapse

Instance Method Details

#category_rule_names_for(rule) ⇒ Object



19
20
21
22
23
24
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 19

def category_rule_names_for(rule)
  Catalog::Category
    .any_in(id: rule.terms)
    .map(&:name)
    .join(', ')
end

#exclude_products_rule_names_for(rule) ⇒ Object



26
27
28
29
30
31
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 26

def exclude_products_rule_names_for(rule)
  Catalog::Product
    .any_in(id: rule.terms)
    .map(&:name)
    .join(', ')
end

#product_rule_operatorsObject



15
16
17
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 15

def product_rule_operators
  ProductRule::OPERATORS.map { |o| [o.humanize.downcase, o] }
end

#product_rule_types_optionsObject



4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 4

def product_rule_types_options
  Search::Storefront::Product.current_product_rule_fields.keys.map do |key|
    translated = t(
      "workarea.admin.fields.#{key}",
      default: key.to_s.humanize
    )

    [translated.downcase, key]
  end
end

#product_rules_show_all_query_string(show_all: true) ⇒ Object



45
46
47
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 45

def product_rules_show_all_query_string(show_all: true)
  "?#{request.query_parameters.merge('show_all' => show_all).to_query}"
end

#render_product_rule_fields_for(rule) ⇒ Object



33
34
35
36
37
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 33

def render_product_rule_fields_for(rule)
  render "workarea/admin/product_rules/fields/#{rule.slug}", rule: rule
rescue ActionView::MissingTemplate
  render "workarea/admin/product_rules/fields/generic", rule: rule
end

#render_product_rule_summary_for(rule) ⇒ Object



39
40
41
42
43
# File 'app/helpers/workarea/admin/product_rules_helper.rb', line 39

def render_product_rule_summary_for(rule)
  render "workarea/admin/product_rules/summaries/#{rule.slug}", rule: rule
rescue ActionView::MissingTemplate
  render "workarea/admin/product_rules/summaries/generic", rule: rule
end