Module: Stay::ControllerHelpers::Currency
- Extended by:
- ActiveSupport::Concern
- Included in:
- Admin::BaseController, Property
- Defined in:
- lib/stay/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
47 48 49 50 51 |
# File 'lib/stay/controller_helpers/currency.rb', line 47 def currency_param return if current_currency == current_store.default_currency current_currency end |
#current_currency ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stay/controller_helpers/currency.rb', line 16 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 Stay::Store.default.default_currency end&.upcase end |
#supported_currencies ⇒ Object
28 29 30 |
# File 'lib/stay/controller_helpers/currency.rb', line 28 def supported_currencies @supported_currencies ||= current_store&.supported_currencies_list end |
#supported_currencies_for_all_stores ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/stay/controller_helpers/currency.rb', line 32 def supported_currencies_for_all_stores @supported_currencies_for_all_stores ||= begin ( Stay::Store.pluck(:supported_currencies).map { |c| c&.split(',') }.flatten + Stay::Store.pluck(:default_currency) ). compact.uniq.map { |code| ::Money::Currency.find(code.strip) } end end |
#supported_currency?(currency_iso_code) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/stay/controller_helpers/currency.rb', line 41 def supported_currency?(currency_iso_code) return false if supported_currencies.nil? supported_currencies.map(&:iso_code).include?(currency_iso_code.upcase) end |