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.

Stripe locale param from URLs when it's not supported

Damian Legawiec02ba2af8f8e2
diff --git a/frontend/app/controllers/spree/store_controller.rb b/frontend/app/controllers/spree/store_controller.rb
index cdf422285d..e5949c824f 100644
--- a/frontend/app/controllers/spree/store_controller.rb
+++ b/frontend/app/controllers/spree/store_controller.rb
@@ -6,6 +6,8 @@ module Spree
skip_before_action :verify_authenticity_token, only: :ensure_cart, raise: false
+ before_action :redirect_to_default_locale
+
def account_link
render partial: 'spree/shared/link_to_account'
fresh_when(etag: [try_spree_current_user, I18n.locale])
@@ -50,5 +52,11 @@ module Spree
def store_last_modified
(current_store.updated_at || Time.current).utc
end
+
+ def redirect_to_default_locale
+ return if params[:locale].blank? || supported_locale?(params[:locale])
+
+ redirect_to url_for(request.parameters.merge(locale: nil))
+ end
end
end
diff --git a/frontend/spec/features/locale_spec.rb b/frontend/spec/features/locale_spec.rb
index de176bdfbd..6be6f1d337 100644
--- a/frontend/spec/features/locale_spec.rb
+++ b/frontend/spec/features/locale_spec.rb
@@ -186,5 +186,23 @@ describe 'setting locale', type: :feature, js: true do
it_behaves_like 'translates UI'
it_behaves_like 'generates proper URLs'
end
+
+ context 'not supported locale' do
+ context 'home page' do
+ before do
+ visit spree.root_path(locale: 'es')
+ end
+
+ it { expect(page).to have_current_path('/') }
+ end
+
+ context 'product page' do
+ before do
+ visit spree.product_path(product, locale: 'es')
+ end
+
+ it { expect(page).to have_current_path(spree.product_path(product)) }
+ end
+ end
end
end