Module: Spree::CurrencyHelper
- Defined in:
- app/helpers/spree/currency_helper.rb
Instance Method Summary collapse
- #currency_money(currency = current_currency) ⇒ Object
-
#currency_options(selected_value = nil) ⇒ String
Returns the list of all currencies as options for a select field.
-
#currency_presentation(currency) ⇒ Array
The currency presentation and ISO code.
-
#currency_symbol(currency) ⇒ String
Returns the currency symbol for the given currency.
-
#preferred_currencies ⇒ Array<Money::Currency>
Returns the list of supported currencies for the current store.
- #preferred_currencies_select_options ⇒ Object
- #should_render_currency_dropdown? ⇒ Boolean
-
#supported_currency_options ⇒ String
Returns the list of supported currencies for the current store as options for a select field.
Instance Method Details
#currency_money(currency = current_currency) ⇒ Object
57 58 59 |
# File 'app/helpers/spree/currency_helper.rb', line 57 def currency_money(currency = current_currency) ::Money::Currency.find(currency) end |
#currency_options(selected_value = nil) ⇒ String
Returns the list of all currencies as options for a select field. By default the value is the default currency of the default store.
7 8 9 10 11 12 13 |
# File 'app/helpers/spree/currency_helper.rb', line 7 def (selected_value = nil) selected_value ||= Spree::Store.default.default_currency currencies = ::Money::Currency.table.map do |_code, details| currency_presentation(details[:iso_code]) end (currencies, :last, :first, selected_value) end |
#currency_presentation(currency) ⇒ Array
Returns the currency presentation and ISO code.
38 39 40 41 42 43 |
# File 'app/helpers/spree/currency_helper.rb', line 38 def currency_presentation(currency) currency_money = currency_money(currency) label = "#{currency_money.name} (#{currency_money.iso_code})" [label, currency] end |
#currency_symbol(currency) ⇒ String
Returns the currency symbol for the given currency.
32 33 34 |
# File 'app/helpers/spree/currency_helper.rb', line 32 def currency_symbol(currency) ::Money::Currency.find(currency).symbol end |
#preferred_currencies ⇒ Array<Money::Currency>
Returns the list of supported currencies for the current store.
47 48 49 50 |
# File 'app/helpers/spree/currency_helper.rb', line 47 def preferred_currencies Spree::Deprecation.warn('preferred_currencies is deprecated and will be removed in Spree 6.0. Use current_store.supported_currencies_list instead.') @preferred_currencies ||= current_store.supported_currencies_list end |
#preferred_currencies_select_options ⇒ Object
52 53 54 55 |
# File 'app/helpers/spree/currency_helper.rb', line 52 def Spree::Deprecation.warn('preferred_currencies_select_options is deprecated and will be removed in Spree 6.0. Use supported_currency_options instead.') preferred_currencies.map { |currency| currency_presentation(currency) } end |
#should_render_currency_dropdown? ⇒ Boolean
23 24 25 26 27 |
# File 'app/helpers/spree/currency_helper.rb', line 23 def should_render_currency_dropdown? return false if current_store.nil? current_store.supported_currencies_list.size > 1 end |
#supported_currency_options ⇒ String
Returns the list of supported currencies for the current store as options for a select field.
17 18 19 20 21 |
# File 'app/helpers/spree/currency_helper.rb', line 17 def return if current_store.nil? ||= current_store.supported_currencies_list.map(&:iso_code).map { |currency| currency_presentation(currency) } end |