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.

Extract supported_currencies_for_all_stores method to CurrencyHelpers

Damian Legawiec7c04765e419d
diff --git a/backend/app/controllers/spree/admin/prices_controller.rb b/backend/app/controllers/spree/admin/prices_controller.rb
index 5fb8f037a6..4b84b3a887 100644
--- a/backend/app/controllers/spree/admin/prices_controller.rb
+++ b/backend/app/controllers/spree/admin/prices_controller.rb
@@ -3,8 +3,6 @@ module Spree
class PricesController < ResourceController
belongs_to 'spree/product', find_by: :slug
- helper_method :supported_currencies_for_all_stores
-
def create
params.require(:vp).permit!
params[:vp].each do |variant_id, prices|
@@ -23,17 +21,6 @@ module Spree
flash[:success] = Spree.t('notice_messages.prices_saved')
redirect_to admin_product_path(parent)
end
-
- private
-
- def supported_currencies_for_all_stores
- @supported_currencies_for_all_stores = begin
- (
- Spree::Store.pluck(:supported_currencies).map { |c| c&.split(',') }.flatten + Spree::Store.pluck(:default_currency)
- ).
- compact.uniq.map { |code| ::Money::Currency.find(code.strip) }
- end
- end
end
end
end
diff --git a/core/lib/spree/core/controller_helpers/currency_helpers.rb b/core/lib/spree/core/controller_helpers/currency_helpers.rb
index b95f823333..1e8fd309db 100644
--- a/core/lib/spree/core/controller_helpers/currency_helpers.rb
+++ b/core/lib/spree/core/controller_helpers/currency_helpers.rb
@@ -4,11 +4,21 @@ module Spree
module CurrencyHelpers
def self.included(receiver)
receiver.send :helper_method, :supported_currencies
+ receiver.send :helper_method, :supported_currencies_for_all_stores
end
def supported_currencies
current_store.supported_currencies_list
end
+
+ def supported_currencies_for_all_stores
+ @supported_currencies_for_all_stores ||= begin
+ (
+ Spree::Store.pluck(:supported_currencies).map { |c| c&.split(',') }.flatten + Spree::Store.pluck(:default_currency)
+ ).
+ compact.uniq.map { |code| ::Money::Currency.find(code.strip) }
+ end
+ end
end
end
end