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.

Admin: Fixed setting calculator for promotion actions

Damian Legawiec9adaa637a714
diff --git a/admin/app/controllers/spree/admin/promotion_actions_controller.rb b/admin/app/controllers/spree/admin/promotion_actions_controller.rb
index 8e0c85631a..852c4e8a38 100644
--- a/admin/app/controllers/spree/admin/promotion_actions_controller.rb
+++ b/admin/app/controllers/spree/admin/promotion_actions_controller.rb
@@ -5,6 +5,8 @@ module Spree
helper_method :allowed_action_types
+ before_action :set_calculator_type, only: [:new]
+
private
def model_class
@@ -34,6 +36,12 @@ module Spree
def collection_url
spree.admin_promotion_path(parent)
end
+
+ def set_calculator_type
+ if @promotion_action.respond_to?(:calculator_type)
+ @promotion_action.calculator_type = @promotion_action.class.calculators.first.name
+ end
+ end
end
end
end
diff --git a/core/app/models/spree/promotion/actions/create_adjustment.rb b/core/app/models/spree/promotion/actions/create_adjustment.rb
index f36e9b8a33..132ec3f005 100644
--- a/core/app/models/spree/promotion/actions/create_adjustment.rb
+++ b/core/app/models/spree/promotion/actions/create_adjustment.rb
@@ -5,8 +5,6 @@ module Spree
include Spree::CalculatedAdjustments
include Spree::AdjustmentSource
- after_initialize -> { self.calculator ||= Calculator::FlatPercentItemTotal.new }
-
def perform(options = {})
order = options[:order]
diff --git a/core/app/models/spree/promotion/actions/create_item_adjustments.rb b/core/app/models/spree/promotion/actions/create_item_adjustments.rb
index 0aaa9650ad..480ed09746 100644
--- a/core/app/models/spree/promotion/actions/create_item_adjustments.rb
+++ b/core/app/models/spree/promotion/actions/create_item_adjustments.rb
@@ -5,8 +5,6 @@ module Spree
include Spree::CalculatedAdjustments
include Spree::AdjustmentSource
- after_initialize -> { self.calculator ||= Calculator::PercentOnLineItem.new }
-
def perform(options = {})
order = options[:order]
promotion = options[:promotion]