Skip to content

Commit

Permalink
Rename Spree::Config.promotions.promotion_adjuster_class
Browse files Browse the repository at this point in the history
This extension point has duplication when used, so we're renaming it to
`Spree::Config.promotions.order_adjuster_class`. This describes better
what it does.
mamhoff committed May 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1fdedd4 commit 1c7f5f0
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
@@ -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
2 changes: 1 addition & 1 deletion core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 614 in core/lib/spree/app_configuration.rb

Codecov / codecov/patch

core/lib/spree/app_configuration.rb#L614

Added line #L614 was not covered by tests
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
4 changes: 2 additions & 2 deletions core/lib/spree/core/null_promotion_configuration.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions core/lib/spree/core/promotion_configuration.rb
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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
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
@@ -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

0 comments on commit 1c7f5f0

Please sign in to comment.