Module: Spree::CurrencyHelper

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

Instance Method Summary collapse

Instance Method Details

#currency_options(selected_value = nil) ⇒ Object



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

def currency_options(selected_value = nil)
  selected_value ||= Spree::Store.default.default_currency
  currencies = ::Money::Currency.table.map do |_code, details|
    iso = details[:iso_code]
    [iso, "#{details[:name]} (#{iso})"]
  end
  options_from_collection_for_select(currencies, :first, :last, selected_value)
end

#currency_presentation(currency) ⇒ Object



28
29
30
31
32
# File 'app/helpers/spree/currency_helper.rb', line 28

def currency_presentation(currency)
  label = [currency_symbol(currency), currency].compact.join(' ')

  [label, currency]
end

#currency_symbol(currency) ⇒ Object



24
25
26
# File 'app/helpers/spree/currency_helper.rb', line 24

def currency_symbol(currency)
  ::Money::Currency.find(currency).symbol
end

#should_render_currency_dropdown?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/helpers/spree/currency_helper.rb', line 18

def should_render_currency_dropdown?
  return false if current_store.nil?

  current_store.supported_currencies_list.size > 1
end

#supported_currency_optionsObject



12
13
14
15
16
# File 'app/helpers/spree/currency_helper.rb', line 12

def supported_currency_options
  return if current_store.nil?

  current_store.supported_currencies_list.map(&:iso_code).map { |currency| currency_presentation(currency) }
end