diff --git a/backend/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb b/backend/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb index 10d4fc31f51..396e727d2ea 100644 --- a/backend/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb +++ b/backend/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb @@ -10,7 +10,7 @@ <%= select_tag( "#{prefix}[calculator_attributes][preferred_currency]", options_for_select( - Money::Currency.all, + Spree::Config.available_currencies, calculator.preferred_currency || Spree::Config[:currency] ), { class: 'custom-select fullwidth' } diff --git a/backend/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb b/backend/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb index 20078ec1a98..be7fd391db1 100644 --- a/backend/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb +++ b/backend/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb @@ -10,7 +10,7 @@ <%= select_tag( "#{prefix}[calculator_attributes][preferred_currency]", options_for_select( - Money::Currency.all, + Spree::Config.available_currencies, calculator.preferred_currency || Spree::Config[:currency] ), { class: 'custom-select fullwidth' } diff --git a/backend/app/views/spree/admin/shared/_js_locale_data.html.erb b/backend/app/views/spree/admin/shared/_js_locale_data.html.erb index d1d1b024757..f9fe2079bbf 100644 --- a/backend/app/views/spree/admin/shared/_js_locale_data.html.erb +++ b/backend/app/views/spree/admin/shared/_js_locale_data.html.erb @@ -15,7 +15,7 @@ Spree.currencyInfo = <%== JSON.dump( - Money::Currency.all.map { |c| + Spree::Config.available_currencies.map { |c| format = if c.symbol == "" || c.symbol_first "%s%v" diff --git a/backend/app/views/spree/admin/shared/_number_with_currency.html.erb b/backend/app/views/spree/admin/shared/_number_with_currency.html.erb index 19632937e0c..babe37772a4 100644 --- a/backend/app/views/spree/admin/shared/_number_with_currency.html.erb +++ b/backend/app/views/spree/admin/shared/_number_with_currency.html.erb @@ -11,6 +11,6 @@ <%= ::Money::Currency.find(currency).iso_code %> <% else %> - <%= f.select currency_attr, ::Money::Currency.all.map(&:iso_code), {include_blank: true}, {required: required, class: 'number-with-currency-select'} %> + <%= f.select currency_attr, Spree::Config.available_currencies.map(&:iso_code), {selected: Spree::Config.currency}, {required: required, class: 'number-with-currency-select'} %> <% end %> diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erb index eaf18379936..c0c35b22288 100644 --- a/backend/app/views/spree/admin/stores/_form.html.erb +++ b/backend/app/views/spree/admin/stores/_form.html.erb @@ -43,7 +43,7 @@ <%= f.field_container :default_currency do %> <%= f.label :default_currency %> <%= f.select :default_currency, - ::Money::Currency.all.map(&:iso_code), + Spree::Config.available_currencies.map(&:iso_code), { include_blank: true }, { class: 'select2 fullwidth' } %> <%= f.error_message_on :default_currency %> diff --git a/backend/spec/javascripts/views/number_with_currency_spec.js b/backend/spec/javascripts/views/number_with_currency_spec.js index 8fb55d2c523..74950650477 100644 --- a/backend/spec/javascripts/views/number_with_currency_spec.js +++ b/backend/spec/javascripts/views/number_with_currency_spec.js @@ -24,15 +24,15 @@ describe("Spree.Views.NumberWithCurrency", function() { loadView(); }); - it("has no currency selected", function() { - expect($select).to.have.$val(''); - expect($symbol).to.have.$text(''); + it("has a default currency selected", function() { + expect($select).to.have.$val('USD'); + expect($symbol).to.have.$text('$'); }); - it("can select USD", function() { - $select.val('USD').trigger('change'); + it("can select CAD", function() { + $select.val('CAD').trigger('change'); - expect($select).to.have.$val('USD'); + expect($select).to.have.$val('CAD'); expect($symbol).to.have.$text('$'); }); diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index aa538aee7c6..fdfa36511ad 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -257,6 +257,15 @@ class AppConfiguration < Preferences::Configuration # @return [Boolean] Indicates if stock management can be restricted by location preference :can_restrict_stock_management, :boolean, default: false + # Allows restricting what currencies will be available. + # + # @!attribute [r] available_currencies + # @returns [Array] An array of available currencies from Money::Currency.all + attr_writer :available_currencies + def available_currencies + @available_currencies ||= ::Money::Currency.all + end + # searcher_class allows spree extension writers to provide their own Search class class_name_attribute :searcher_class, default: 'Spree::Core::Search::Base'