Module: ProductsHelper
- Defined in:
- app/helpers/products_helper.rb
Instance Method Summary collapse
- #format_price(price, options = {}) ⇒ Object
-
#product_description(product) ⇒ Object
converts line breaks in product description into <p> tags (for html display purposes).
-
#product_price(product_or_variant, options = {}) ⇒ Object
returns the price of the product to show for display purposes.
-
#seo_url(taxon, product = nil) ⇒ Object
generates nested url to product based on supplied taxon.
-
#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
#format_price(price, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/products_helper.rb', line 25 def format_price(price, ={}) .assert_valid_keys(:show_vat_text) .reverse_merge! :show_vat_text => Spree::Config[:show_price_inc_vat] formatted_price = number_to_currency(price) if [:show_vat_text] I18n.t(:price_with_vat_included, :price => formatted_price) else formatted_price end end |
#product_description(product) ⇒ Object
converts line breaks in product description into <p> tags (for html display purposes)
37 38 39 |
# File 'app/helpers/products_helper.rb', line 37 def product_description(product) raw(product.description.gsub(/^(.*)$/, '<p>\1</p>')) end |
#product_price(product_or_variant, options = {}) ⇒ Object
returns the price of the product to show for display purposes
16 17 18 19 20 21 22 23 |
# File 'app/helpers/products_helper.rb', line 16 def product_price(product_or_variant, ={}) .assert_valid_keys(:format_as_currency, :show_vat_text) .reverse_merge! :format_as_currency => true, :show_vat_text => Spree::Config[:show_price_inc_vat] amount = product_or_variant.price amount += Calculator::Vat.calculate_tax_on(product_or_variant) if Spree::Config[:show_price_inc_vat] .delete(:format_as_currency) ? format_price(amount, ) : amount end |
#seo_url(taxon, product = nil) ⇒ Object
generates nested url to product based on supplied taxon
42 43 44 45 46 47 |
# File 'app/helpers/products_helper.rb', line 42 def seo_url(taxon, product = nil) return '/t/' + taxon.permalink if product.nil? warn "DEPRECATION: the /t/taxon-permalink/p/product-permalink urls are "+ "not used anymore. Use product_url instead. (called from #{caller[0]})" return product_url(product) 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)
4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/products_helper.rb', line 4 def variant_price_diff(variant) return product_price(variant) unless variant.product.master.price diff = product_price(variant, :format_as_currency => false) - product_price(variant.product, :format_as_currency => false) return nil if diff == 0 if diff > 0 "(#{t("add")}: #{format_price diff.abs})" else "(#{t("subtract")}: #{format_price diff.abs})" end end |