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.

Always sort supported locale/currency alphabetically

Damian Legawiec95bbe4f24874
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 2f3bad830e..4298e09805 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -51,14 +51,14 @@ module Spree
end
def supported_currencies_list
- @supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).map(&:to_s).map do |code|
+ @supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).sort.map(&:to_s).map do |code|
::Money::Currency.find(code.strip)
end.uniq.compact
end
def supported_locales_list
# TODO: add support of multiple supported languages to a single Store
- @supported_locales_list ||= (read_attribute(:supported_locales).to_s.split(',') << default_locale).compact.uniq
+ @supported_locales_list ||= (read_attribute(:supported_locales).to_s.split(',') << default_locale).compact.uniq.sort
end
def unique_name
diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rb
index ad97935704..2233798d44 100644
--- a/core/spec/models/spree/store_spec.rb
+++ b/core/spec/models/spree/store_spec.rb
@@ -244,7 +244,7 @@ describe Spree::Store, type: :model do
it 'returns supported currencies list' do
expect(store.supported_currencies_list).to contain_exactly(
- ::Money::Currency.find('USD'), ::Money::Currency.find('EUR')
+ ::Money::Currency.find('EUR'), ::Money::Currency.find('USD')
)
end
end
@@ -266,7 +266,7 @@ describe Spree::Store, type: :model do
it 'returns supported currencies list' do
expect(store.supported_locales_list).to be_an_instance_of(Array)
- expect(store.supported_locales_list).to contain_exactly('fr', 'de')
+ expect(store.supported_locales_list).to contain_exactly('de', 'fr')
end
end