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
Use guard clause for scenarios where current_store is not defined
Damian Legawiecf5e3dc1a6023
diff --git a/core/app/finders/spree/products/find.rb b/core/app/finders/spree/products/find.rbindex c2f2ccfe4f..b633d258bb 100644--- a/core/app/finders/spree/products/find.rb+++ b/core/app/finders/spree/products/find.rb@@ -103,13 +103,13 @@ module Spreewhere(spree_prices: {amount: price.min..price.max,- currency: currency.upcase+ currency: currency&.upcase})enddef by_currency(products)- return products if price?+ return products unless currency?products.joins(master: :prices).where(spree_prices: { currency: currency.upcase })enddiff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex c461dffc61..dcb1feb748 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -192,7 +192,7 @@ module Spreeenddef price_in(currency)- prices.detect { |price| price.currency == currency.upcase } || prices.build(currency: currency.upcase)+ prices.detect { |price| price.currency == currency&.upcase } || prices.build(currency: currency&.upcase)enddef amount_in(currency)diff --git a/core/lib/spree/core/controller_helpers/currency.rb b/core/lib/spree/core/controller_helpers/currency.rbindex 6a52b0651b..91d471c829 100644--- a/core/lib/spree/core/controller_helpers/currency.rb+++ b/core/lib/spree/core/controller_helpers/currency.rb@@ -16,13 +16,15 @@ module Spreesession[:currency]elsif params[:currency].present? && supported_currency?(params[:currency])params[:currency]- else+ elsif current_store.present?current_store.default_currency- end.upcase+ else+ Spree::Config[:currency]+ end&.upcaseenddef supported_currencies- @supported_currencies ||= current_store.supported_currencies_list+ @supported_currencies ||= current_store&.supported_currencies_listenddef supported_currencies_for_all_stores@@ -35,6 +37,8 @@ module Spreeenddef supported_currency?(currency_iso_code)+ return false if supported_currencies.nil?+supported_currencies.map(&:iso_code).include?(currency_iso_code.upcase)endenddiff --git a/core/lib/spree/core/controller_helpers/locale.rb b/core/lib/spree/core/controller_helpers/locale.rbindex ac57b85512..ed56bc4166 100644--- a/core/lib/spree/core/controller_helpers/locale.rb+++ b/core/lib/spree/core/controller_helpers/locale.rb@@ -19,8 +19,6 @@ module Spreeenddef current_locale- # session support was previously in SpreeI18n so we would like to keep it for now- # for easer upgrade@current_locale ||= if defined?(session) && session.key?(:locale) && supported_locale?(session[:locale])session[:locale]elsif params[:locale].present? && supported_locale?(params[:locale])@@ -28,15 +26,17 @@ module Spreeelsif respond_to?(:config_locale, true) && config_locale.present?config_localeelse- current_store.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale+ current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_localeendenddef supported_locales- @supported_locales ||= current_store.supported_locales_list+ @supported_locales ||= current_store&.supported_locales_listenddef supported_locale?(locale_code)+ return false if supported_locales.nil?+supported_locales.include?(locale_code&.to_s)enddiff --git a/frontend/spec/features/product_prices_spec.rb b/frontend/spec/features/product_prices_spec.rbindex fcd86fa451..ba220ef1a2 100644--- a/frontend/spec/features/product_prices_spec.rb+++ b/frontend/spec/features/product_prices_spec.rb@@ -23,7 +23,7 @@ describe 'Product with prices in multiple currencies', type: :feature, js: truevisit spree.products_pathexpect(page).to have_text '£23.00'find('#header #internationalization-button').click- expect(page).to have_select('currency', selected: 'GBP')+ expect(page).to have_select('switch_to_currency', selected: 'GBP')endendend