Module: Spree::ProductsHelper
- Defined in:
- app/helpers/spree/products_helper.rb
Instance Method Summary collapse
-
#product_description(product) ⇒ Object
converts line breaks in product description into <p> tags (for html display purposes).
- #variant_images_hash(product) ⇒ Object
-
#variant_price_diff(variant) ⇒ Object
returns the formatted change in price (from the master price) for the specified variant (or simply return the variant price if no master price was supplied).
Instance Method Details
#product_description(product) ⇒ Object
converts line breaks in product description into <p> tags (for html display purposes)
16 17 18 |
# File 'app/helpers/spree/products_helper.rb', line 16 def product_description(product) raw(product.description.gsub(/(.*?)\n\n/m, '<p>\1</p>\n\n')) end |
#variant_images_hash(product) ⇒ Object
20 21 22 |
# File 'app/helpers/spree/products_helper.rb', line 20 def variant_images_hash(product) product.variant_images.inject({}) { |h, img| (h[img.viewable_id] ||= []) << img; h } end |
#variant_price_diff(variant) ⇒ Object
returns the formatted change in price (from the master price) for the specified variant (or simply return the variant price if no master price was supplied)
5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/spree/products_helper.rb', line 5 def variant_price_diff(variant) diff = variant.price - variant.product.price return nil if diff == 0 if diff > 0 "(#{t(:add)}: #{number_to_currency diff.abs})" else "(#{t(:subtract)}: #{number_to_currency diff.abs})" end end |