Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixes #13168 undefined currency_options_for_select
Damian Legawieca2f31d2a4ea3
diff --git a/admin/app/views/spree/admin/promotion_rules/forms/_currency.html.erb b/admin/app/views/spree/admin/promotion_rules/forms/_currency.html.erbindex 340cb92f0e..f79f2e0896 100644--- a/admin/app/views/spree/admin/promotion_rules/forms/_currency.html.erb+++ b/admin/app/views/spree/admin/promotion_rules/forms/_currency.html.erb@@ -1,9 +1,6 @@<div class="form-group"><%= f.select :preferred_currency,- currency_options_for_select(- f.object.preferred_currency,- current_store.supported_currencies.split(',')- ),+ options_for_select(supported_currency_options, f.object.preferred_currency),{},{ data: { controller: 'autocomplete-select' } }%>diff --git a/admin/app/views/spree/admin/store_credits/_form.html.erb b/admin/app/views/spree/admin/store_credits/_form.html.erbindex 303a2c9c72..71225ef6f8 100644--- a/admin/app/views/spree/admin/store_credits/_form.html.erb+++ b/admin/app/views/spree/admin/store_credits/_form.html.erb@@ -1,3 +1,3 @@<%= f.spree_number_field :amount, label: Spree.t(:amount), min: 0.01, step: 0.01, required: true, disabled: !f.object.editable? %>-<%= f.spree_select :currency, preferred_currencies_select_options, { label: Spree.t(:currency), autocomplete: true }, { data: { enable_button_target: 'input', store_form_target: 'currency' } } %>+<%= f.spree_select :currency, options_for_select(supported_currency_options, f.object.currency), { label: Spree.t(:currency), autocomplete: true }, { data: { enable_button_target: 'input', store_form_target: 'currency' } } %><%= f.spree_text_area :memo %>diff --git a/core/app/helpers/spree/currency_helper.rb b/core/app/helpers/spree/currency_helper.rbindex 4459ef5dc1..f8d35a5d1d 100644--- a/core/app/helpers/spree/currency_helper.rb+++ b/core/app/helpers/spree/currency_helper.rb@@ -1,18 +1,23 @@module Spreemodule CurrencyHelper+ # Returns the list of all currencies as options for a select field.+ # By default the value is the default currency of the default store.+ # @param selected_value [String] the selected value+ # @return [String] the options for a select fielddef currency_options(selected_value = nil)selected_value ||= Spree::Store.default.default_currencycurrencies = ::Money::Currency.table.map do |_code, details|- iso = details[:iso_code]- [iso, "#{details[:name]} (#{iso})"]+ currency_presentation(details[:iso_code])end- options_from_collection_for_select(currencies, :first, :last, selected_value)+ options_from_collection_for_select(currencies, :last, :first, selected_value)end+ # Returns the list of supported currencies for the current store as options for a select field.+ # @return [String] the options for a select fielddef supported_currency_optionsreturn if current_store.nil?- current_store.supported_currencies_list.map(&:iso_code).map { |currency| currency_presentation(currency) }+ @supported_currency_options ||= current_store.supported_currencies_list.map(&:iso_code).map { |currency| currency_presentation(currency) }enddef should_render_currency_dropdown?@@ -21,22 +26,32 @@ module Spreecurrent_store.supported_currencies_list.size > 1end+ # Returns the currency symbol for the given currency.+ # @param currency [String] the currency ISO code+ # @return [String] the currency symboldef currency_symbol(currency)::Money::Currency.find(currency).symbolend+ # @param currency [String] the currency ISO code+ # @return [Array] the currency presentation and ISO codedef currency_presentation(currency)- label = [currency_symbol(currency), currency].compact.join(' ')+ currency_money = currency_money(currency)+ label = "#{currency_money.name} (#{currency_money.iso_code})"[label, currency]end+ # Returns the list of supported currencies for the current store.+ # @return [Array<Money::Currency>] the list of supported currenciesdef preferred_currencies+ Spree::Deprecation.warn('preferred_currencies is deprecated and will be removed in Spree 6.0. Use current_store.supported_currencies_list instead.')@preferred_currencies ||= current_store.supported_currencies_listenddef preferred_currencies_select_options- preferred_currencies.map { |currency| ["#{currency.name} - #{currency.iso_code}", currency] }+ Spree::Deprecation.warn('preferred_currencies_select_options is deprecated and will be removed in Spree 6.0. Use supported_currency_options instead.')+ preferred_currencies.map { |currency| currency_presentation(currency) }enddef currency_money(currency = current_currency)diff --git a/core/spec/helpers/currency_helper_spec.rb b/core/spec/helpers/currency_helper_spec.rbindex 8fefafcbcd..496af1f190 100644--- a/core/spec/helpers/currency_helper_spec.rb+++ b/core/spec/helpers/currency_helper_spec.rb@@ -9,7 +9,7 @@ describe Spree::CurrencyHelper, type: :helper doenddescribe '#supported_currency_options' do- it { expect(supported_currency_options).to contain_exactly(['zł PLN', 'PLN'], ['£ GBP', 'GBP'], ['€ EUR', 'EUR']) }+ it { expect(supported_currency_options).to contain_exactly(['Polish Złoty (PLN)', 'PLN'], ['British Pound (GBP)', 'GBP'], ['Euro (EUR)', 'EUR']) }enddescribe '#should_render_currency_dropdown?' do@@ -29,7 +29,7 @@ describe Spree::CurrencyHelper, type: :helper doenddescribe '#currency_presentation' do- it { expect(currency_presentation('EUR')).to eq(['€ EUR', 'EUR']) }+ it { expect(currency_presentation('EUR')).to eq(['Euro (EUR)', 'EUR']) }enddescribe '#currency_money' do