Skip to content

Commit

Permalink
Merge pull request solidusio#5752 from mamhoff/rename-adjuster-class
Browse files Browse the repository at this point in the history
Rename Spree::Config.promotions.promotion_adjuster_class
  • Loading branch information
kennyadsl authored May 21, 2024
2 parents ce509de + 1c7f5f0 commit 64f747e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def ensure_inventory_units
end

def ensure_promotions_eligible
Spree::Config.promotions.promotion_adjuster_class.new(self).call
Spree::Config.promotions.order_adjuster_class.new(self).call

if promo_total_changed?
restart_checkout_flow
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def log_state_change(name)
end

def update_promotions
Spree::Config.promotions.promotion_adjuster_class.new(order).call
Spree::Config.promotions.order_adjuster_class.new(order).call
end

def update_taxes
Expand Down
16 changes: 11 additions & 5 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,21 @@ def promotions
class << self
private

def promotions_deprecation_message(method)
def promotions_deprecation_message(method, new_method_name = nil)
"The `Spree::Config.#{method}` preference is deprecated and will be removed in Solidus 5.0. " \
"Use `Spree::Config.promotions.#{method}` instead"
"Use `Spree::Config.promotions.#{new_method_name || method}` instead"
end
end

delegate :promotion_adjuster_class, :promotion_adjuster_class=, to: :promotions
deprecate promotion_adjuster_class: promotions_deprecation_message("promotion_adjuster_class"), deprecator: Spree.deprecator
deprecate "promotion_adjuster_class=": promotions_deprecation_message("promotion_adjuster_class="), deprecator: Spree.deprecator
def promotion_adjuster_class
promotions.order_adjuster_class
end

def promotion_adjuster_class=(klass)
promotions.order_adjuster_class = klass
end
deprecate promotion_adjuster_class: promotions_deprecation_message("promotion_adjuster_class", "order_adjuster_class"), deprecator: Spree.deprecator
deprecate "promotion_adjuster_class=": promotions_deprecation_message("promotion_adjuster_class=", "order_adjuster_class="), deprecator: Spree.deprecator

delegate :promotion_chooser_class, :promotion_chooser_class=, to: :promotions
deprecate promotion_chooser_class: promotions_deprecation_message("promotion_chooser_class"), deprecator: Spree.deprecator
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/core/null_promotion_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Spree
module Core
class NullPromotionConfiguration < Spree::Preferences::Configuration
# promotion_adjuster_class allows extensions to provide their own Promotion Adjuster
class_name_attribute :promotion_adjuster_class, default: 'Spree::NullPromotionAdjuster'
# order_adjuster_class allows extensions to provide their own Order Adjuster
class_name_attribute :order_adjuster_class, default: 'Spree::NullPromotionAdjuster'

# Allows providing a different coupon code handler.
# @!attribute [rw] coupon_code_handler_class
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/core/promotion_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class PromotionConfiguration < Spree::Preferences::Configuration
# promotion_chooser_class allows extensions to provide their own PromotionChooser
class_name_attribute :promotion_chooser_class, default: 'Spree::PromotionChooser'

# promotion_adjuster_class allows extensions to provide their own Promotion Adjuster
class_name_attribute :promotion_adjuster_class, default: 'Spree::Promotion::OrderAdjustmentsRecalculator'
# order_adjuster_class allows extensions to provide their own Order Adjuster
class_name_attribute :order_adjuster_class, default: 'Spree::Promotion::OrderAdjustmentsRecalculator'

# promotion_finder_class allows extensions to provide their own Promotion Finder
class_name_attribute :promotion_finder_class, default: 'Spree::PromotionFinder'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
subject(:config) { described_class.new }

it "uses the null promotion adjuster class by default" do
expect(config.promotion_adjuster_class).to eq Spree::NullPromotionAdjuster
expect(config.order_adjuster_class).to eq Spree::NullPromotionAdjuster
end

it "uses the null coupon code handler class by default" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/lib/spree/core/promotion_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

it "uses order adjustments recalculator class by default" do
expect(config.promotion_adjuster_class).to eq Spree::Promotion::OrderAdjustmentsRecalculator
expect(config.order_adjuster_class).to eq Spree::Promotion::OrderAdjustmentsRecalculator
end

it "uses promotion handler coupon class by default" do
Expand Down

0 comments on commit 64f747e

Please sign in to comment.