Module: Spree::ProductsHelper

Defined in:
app/helpers/spree/products_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_taxonomiesObject



56
57
58
# File 'app/helpers/spree/products_helper.rb', line 56

def get_taxonomies
  @taxonomies ||= Spree::Taxonomy.includes(root: :children)
end

#line_item_description(variant) ⇒ Object



42
43
44
45
46
# File 'app/helpers/spree/products_helper.rb', line 42

def line_item_description(variant)
  ActiveSupport::Deprecation.warn "line_item_description(variant) is deprecated and may be removed from future releases, use line_item_description_text(line_item.description) instead.", caller

  line_item_description_text(variant.product.description)
end

#line_item_description_text(description_text) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/spree/products_helper.rb', line 48

def line_item_description_text description_text
  if description_text.present?
    truncate(strip_tags(description_text.gsub(' ', ' ')), length: 100)
  else
    Spree.t(:product_has_no_description)
  end
end

#product_description(product) ⇒ Object

converts line breaks in product description into <p> tags (for html display purposes)



34
35
36
37
38
39
40
# File 'app/helpers/spree/products_helper.rb', line 34

def product_description(product)
  if Spree::Config[:show_raw_product_description]
    raw(product.description)
  else
    raw(product.description.gsub(/(.*?)\r?\n\r?\n/m, '<p>\1</p>'))
  end
end

#variant_full_price(variant) ⇒ Object

returns the formatted full price for the variant, if at least one variant price differs from product price



26
27
28
29
30
31
# File 'app/helpers/spree/products_helper.rb', line 26

def variant_full_price(variant)
  product = variant.product
  unless product.variants.active(current_currency).all? { |v| v.price == product.price }
    Spree::Money.new(variant.price, { currency: current_currency }).to_html
  end
end

#variant_price(variant) ⇒ Object

returns the formatted price for the specified variant as a full price or a difference depending on configuration



4
5
6
7
8
9
10
# File 'app/helpers/spree/products_helper.rb', line 4

def variant_price(variant)
  if Spree::Config[:show_variant_full_price]
    variant_full_price(variant)
  else
    variant_price_diff(variant)
  end
end

#variant_price_diff(variant) ⇒ Object

returns the formatted price for the specified variant as a difference from product price



14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/spree/products_helper.rb', line 14

def variant_price_diff(variant)
  diff = variant.amount_in(current_currency) - variant.product.amount_in(current_currency)
  return nil if diff == 0
  amount = Spree::Money.new(diff.abs, { currency: current_currency }).to_html
  if diff > 0
    "(#{Spree.t(:add)}: #{amount})".html_safe
  else
    "(#{Spree.t(:subtract)}: #{amount})".html_safe
  end
end