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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add currency param in URLs to bust HTTP cache
Damian Legawiecc86256c766c4
diff --git a/core/lib/spree/core/controller_helpers/currency.rb b/core/lib/spree/core/controller_helpers/currency.rbindex 91d471c829..c9599f6350 100644--- a/core/lib/spree/core/controller_helpers/currency.rb+++ b/core/lib/spree/core/controller_helpers/currency.rb@@ -9,6 +9,7 @@ module Spreehelper_method :supported_currencies_for_all_storeshelper_method :current_currencyhelper_method :supported_currency?+ helper_method :currency_paramenddef current_currency@@ -41,6 +42,12 @@ module Spreesupported_currencies.map(&:iso_code).include?(currency_iso_code.upcase)end++ def currency_param+ return if current_currency == current_store.default_currency++ current_currency+ endendendenddiff --git a/core/spec/lib/spree/core/controller_helpers/currency_spec.rb b/core/spec/lib/spree/core/controller_helpers/currency_spec.rbindex 6b8da11529..9e0fd37572 100644--- a/core/spec/lib/spree/core/controller_helpers/currency_spec.rb+++ b/core/spec/lib/spree/core/controller_helpers/currency_spec.rb@@ -26,4 +26,20 @@ describe Spree::Core::ControllerHelpers::Currency, type: :controller doexpect(controller.supported_currencies).to include(::Money::Currency.find(currency))endend++ describe '#currency_param' do+ let!(:store) { create :store, default: true, default_currency: 'EUR', supported_currencies: 'EUR,GBP' }++ context 'same as store default locale' do+ before { controller.params = { currency: 'EUR' } }++ it { expect(controller.currency_param).to eq(nil) }+ end++ context 'different than store locale' do+ before { controller.params = { currency: 'GBP' } }++ it { expect(controller.currency_param).to eq('GBP') }+ end+ endenddiff --git a/frontend/app/controllers/concerns/spree/locale_urls.rb b/frontend/app/controllers/concerns/spree/locale_urls.rbindex dda4f9a7b2..5905d6bdaf 100644--- a/frontend/app/controllers/concerns/spree/locale_urls.rb+++ b/frontend/app/controllers/concerns/spree/locale_urls.rb@@ -9,9 +9,7 @@ module Spreeprivatedef default_url_options- return super if locale_param.nil?-- super.merge(locale: locale_param)+ super.merge(locale: locale_param, currency: currency_param)enddef redirect_to_default_localediff --git a/frontend/spec/features/product_prices_spec.rb b/frontend/spec/features/product_prices_spec.rbindex c187eadce5..78cb4dd374 100644--- a/frontend/spec/features/product_prices_spec.rb+++ b/frontend/spec/features/product_prices_spec.rb@@ -20,6 +20,7 @@ describe 'Product with prices in multiple currencies', type: :feature, js: trueexpect(page).to have_text '£23.00'visit spree.products_pathexpect(page).to have_text '£23.00'+ expect(page).to have_link product.name, href: "/products/#{product.slug}?currency=GBP"open_i18n_menuexpect(page).to have_select('switch_to_currency', selected: 'GBP')end