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.

Add memoization for Crurrency#current_currency and supported_currencies

Damian Legawiec3d9da22b9306
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 4807d3cc60..47f9061fbe 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -44,7 +44,7 @@ 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|
+ (read_attribute(:supported_currencies).to_s.split(',') << default_currency).map(&:to_s).map do |code|
::Money::Currency.find(code.strip)
end.uniq.compact
end
diff --git a/core/lib/spree/core/controller_helpers/currency.rb b/core/lib/spree/core/controller_helpers/currency.rb
index fe9050946c..fb358e1639 100644
--- a/core/lib/spree/core/controller_helpers/currency.rb
+++ b/core/lib/spree/core/controller_helpers/currency.rb
@@ -12,17 +12,19 @@ module Spree
end
def current_currency
- if defined?(session) && session.key?(:currency) && supported_currency?(session[:currency])
- session[:currency]
- elsif params[:currency].present? && supported_currency?(params[:currency])
- params[:currency]
- else
- current_store.default_currency
- end
+ # session support was previously in SpreeMultiCurrency so we would like
+ # to keep it for now
+ @current_currency ||= if defined?(session) && session.key?(:currency) && supported_currency?(session[:currency])
+ session[:currency]
+ elsif params[:currency].present? && supported_currency?(params[:currency])
+ params[:currency]
+ else
+ current_store.default_currency
+ end
end
def supported_currencies
- current_store.supported_currencies_list
+ @supported_currencies ||= current_store.supported_currencies_list
end
def supported_currencies_for_all_stores