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 ⇒ Object
- #current_currency ⇒ Object
- #supported_currencies ⇒ Object
- #supported_currencies_for_all_stores ⇒ Object
- #supported_currency?(currency_iso_code) ⇒ Boolean
Instance Method Details
#currency_param ⇒ Object
48 49 50 51 52 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 48 def currency_param return if current_currency == current_store.default_currency current_currency end |
#current_currency ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 17 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 ⇒ Object
29 30 31 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 29 def supported_currencies @supported_currencies ||= current_store&.supported_currencies_list end |
#supported_currencies_for_all_stores ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 33 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
42 43 44 45 46 |
# File 'lib/spree/core/controller_helpers/currency.rb', line 42 def supported_currency?(currency_iso_code) return false if supported_currencies.nil? supported_currencies.map(&:iso_code).include?(currency_iso_code.upcase) end |