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.

Guard against missing locale in `Spree::Current` if both store and ma… (#14163)

Damian Legawiec69ca947de0a0
diff --git a/spree/core/app/models/spree/current.rb b/spree/core/app/models/spree/current.rb
index ace0f857ac..a945a2bd11 100644
--- a/spree/core/app/models/spree/current.rb
+++ b/spree/core/app/models/spree/current.rb
@@ -32,10 +32,10 @@ module Spree
end
# Returns the current locale.
- # Fallback: market default locale -> store default locale.
+ # Fallback: market default locale -> store default locale -> I18n default.
# @return [String] locale code, e.g. +"en"+, +"de"+
def locale
- super || market&.default_locale || store&.default_locale
+ super || market&.default_locale.presence || store&.default_locale.presence || I18n.default_locale.to_s
end
# Returns the current tax zone.
diff --git a/spree/core/spec/models/spree/current_spec.rb b/spree/core/spec/models/spree/current_spec.rb
index 86fcbfdf1a..0758ae0082 100644
--- a/spree/core/spec/models/spree/current_spec.rb
+++ b/spree/core/spec/models/spree/current_spec.rb
@@ -138,6 +138,14 @@ RSpec.describe Spree::Current do
expect(described_class.locale).to eq('en')
end
end
+
+ context 'when the store has no default locale' do
+ let!(:store) { create(:store, default: true, default_locale: nil) }
+
+ it 'falls back to the I18n default locale' do
+ expect(described_class.locale).to eq(I18n.default_locale.to_s)
+ end
+ end
end
describe '#market' do