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.

Added CurencyHelper#should_render_currency_dropdown?

Damian Legawiecfb9c2107eb10
diff --git a/core/app/helpers/spree/currency_helper.rb b/core/app/helpers/spree/currency_helper.rb
index a14eef3d51..f421c68124 100644
--- a/core/app/helpers/spree/currency_helper.rb
+++ b/core/app/helpers/spree/currency_helper.rb
@@ -8,5 +8,17 @@ module Spree
end
options_from_collection_for_select(currencies, :first, :last, selected_value)
end
+
+ def supported_currency_options
+ return if current_store.nil?
+
+ current_store.supported_currencies_list.map(&:iso_code)
+ end
+
+ def should_render_currency_dropdown?
+ return false if current_store.nil?
+
+ current_store.supported_currencies_list.size > 1
+ end
end
end
diff --git a/core/spec/helpers/currency_helper_spec.rb b/core/spec/helpers/currency_helper_spec.rb
new file mode 100644
index 0000000000..9fae1f65c6
--- /dev/null
+++ b/core/spec/helpers/currency_helper_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+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') }
+ end
+
+ describe '#should_render_currency_dropdown?' do
+ context 'store with multiple currencies' do
+ it { expect(should_render_currency_dropdown?).to be_truthy }
+ end
+
+ context 'store with single currency' do
+ let(:current_store) { create(:store, default_currency: 'EUR', supported_currencies: 'EUR') }
+
+ it { expect(should_render_currency_dropdown?).to be_falsey }
+ end
+ end
+end