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 in JS localized paths

Damian Legawiec29c953698849
diff --git a/core/app/assets/javascripts/spree.js b/core/app/assets/javascripts/spree.js
index 26fd681ad8..4878b6ca0f 100644
--- a/core/app/assets/javascripts/spree.js
+++ b/core/app/assets/javascripts/spree.js
@@ -22,16 +22,20 @@ Spree.pathFor = function (path) {
}
Spree.localizedPathFor = function(path) {
- if (typeof (SPREE_LOCALE) !== 'undefined') {
- if (path.match(/api\/v/)) {
- if (path.match(/\?/)) {
- path = path + '&locale=' + SPREE_LOCALE
- } else {
- path = path + '?locale=' + SPREE_LOCALE
- }
+ if (typeof (SPREE_LOCALE) !== 'undefined' && typeof (SPREE_CURRENCY) !== 'undefined') {
+ var fullUrl = new URL(Spree.pathFor(path))
+ var params = fullUrl.searchParams
+ var pathName = fullUrl.pathname
+
+ params.set('currency', SPREE_CURRENCY)
+
+ if (pathName.match(/api\/v/)) {
+ params.set('locale', SPREE_LOCALE)
} else {
- path = SPREE_LOCALE + '/' + path
+ pathName = SPREE_LOCALE + '/' + pathName
}
+
+ path = pathName + '?' + params.toString()
}
return Spree.pathFor(path)
}