Module: Spree::Core::ControllerHelpers::Currency
- Extended by:
- ActiveSupport::Concern
- Included in:
- BaseController
- Defined in:
- lib/spree/core/controller_helpers/currency.rb
Instance Method Summary collapse
-
#currency_param ⇒ String
Returns the currency parameter from the request.
-
#current_currency ⇒ String
Returns the currently selected currency.
-
#supported_currencies ⇒ Array<Money::Currency>
Returns the list of supported currencies for the current store.
-
#supported_currencies_for_all_stores ⇒ Array<String>
Returns the list of supported currencies for all stores.
-
#supported_currency?(currency_iso_code) ⇒ Boolean
Checks if the given currency is supported.
Instance Method Details
#currency_param ⇒ String
Returns the currency parameter from the request.
59 60 61 62 63 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 59 def currency_param return if current_currency == current_store.default_currency current_currency end |
#current_currency ⇒ String
Returns the currently selected currency.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 19 def current_currency @current_currency ||= if defined?(session) && session.key?(:currency) && supported_currency?(session[:currency]) session[:currency] elsif params[:currency].present? && supported_currency?(params[:currency]) params[:currency] elsif current_store.present? current_store.default_currency else Spree::Store.default.default_currency end&.upcase end |
#supported_currencies ⇒ Array<Money::Currency>
Returns the list of supported currencies for the current store.
33 34 35 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 33 def supported_currencies @supported_currencies ||= current_store&.supported_currencies_list end |
#supported_currencies_for_all_stores ⇒ Array<String>
Returns the list of supported currencies for all stores.
39 40 41 42 43 44 45 46 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 39 def supported_currencies_for_all_stores @supported_currencies_for_all_stores ||= begin ( Spree::Store.pluck(:supported_currencies).map { |c| c&.split(',') }.flatten + Spree::Store.pluck(:default_currency) ). compact.uniq.map { |code| ::Money::Currency.find(code.strip) } end end |
#supported_currency?(currency_iso_code) ⇒ Boolean
Checks if the given currency is supported.
51 52 53 54 55 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 51 def supported_currency?(currency_iso_code) return false if supported_currencies.nil? supported_currencies.map(&:iso_code).include?(currency_iso_code.upcase) end |