Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Include currency symbol in currency dropdown

Damian Legawiec91fa208380e2
diff --git a/core/app/helpers/spree/currency_helper.rb b/core/app/helpers/spree/currency_helper.rb
index f421c68124..cc55ac1aa5 100644
--- a/core/app/helpers/spree/currency_helper.rb
+++ b/core/app/helpers/spree/currency_helper.rb
@@ -12,7 +12,7 @@ module Spree
def supported_currency_options
return if current_store.nil?
- current_store.supported_currencies_list.map(&:iso_code)
+ current_store.supported_currencies_list.map(&:iso_code).map { |currency| currency_presentation(currency) }
end
def should_render_currency_dropdown?
@@ -20,5 +20,15 @@ module Spree
current_store.supported_currencies_list.size > 1
end
+
+ def currency_symbol(currency)
+ ::Money::Currency.find(currency).symbol
+ end
+
+ def currency_presentation(currency)
+ label = [currency_symbol(currency), currency].compact.join(' ')
+
+ [label, currency]
+ end
end
end
diff --git a/core/spec/helpers/currency_helper_spec.rb b/core/spec/helpers/currency_helper_spec.rb
index 9fae1f65c6..559391d16b 100644
--- a/core/spec/helpers/currency_helper_spec.rb
+++ b/core/spec/helpers/currency_helper_spec.rb
@@ -4,7 +4,7 @@ describe Spree::CurrencyHelper, type: :helper do
let(:current_store) { create(:store, default_currency: 'EUR', supported_currencies: 'EUR,PLN,GBP') }
describe '#supported_currency_options' do
- it { expect(supported_currency_options).to contain_exactly('EUR', 'GBP', 'PLN') }
+ it { expect(supported_currency_options).to contain_exactly(['zł PLN', 'PLN'], ['£ GBP', 'GBP'], ['€ EUR', 'EUR']) }
end
describe '#should_render_currency_dropdown?' do
@@ -18,4 +18,12 @@ describe Spree::CurrencyHelper, type: :helper do
it { expect(should_render_currency_dropdown?).to be_falsey }
end
end
+
+ describe '#currency_symbol' do
+ it { expect(currency_symbol('EUR')).to eq('€') }
+ end
+
+ describe '#currency_presentation' do
+ it { expect(currency_presentation('EUR')).to eq(['€ EUR', 'EUR']) }
+ end
end
diff --git a/frontend/spec/features/product_prices_spec.rb b/frontend/spec/features/product_prices_spec.rb
index 5ce3ace7cc..814861b4c3 100644
--- a/frontend/spec/features/product_prices_spec.rb
+++ b/frontend/spec/features/product_prices_spec.rb
@@ -24,7 +24,7 @@ describe 'Product with prices in multiple currencies', type: :feature, js: true
expect(page).to have_text '£23.00'
expect(page).to have_link product.name, href: "/products/#{product.slug}?currency=GBP"
open_i18n_menu
- expect(page).to have_select('switch_to_currency', selected: 'GBP')
+ expect(page).to have_select('switch_to_currency', selected: '£ GBP')
close_i18n_menu
switch_to_currency('USD')
expect(page).to have_text '$19.99'