Skip to content

Commit fa69480

Browse files
committed
Deprecate Level concerns
The `LineItemLevelCondition`, `OrderLevelCondition`, and `ShipmentLevelCondition` concerns are awkwardly named, and there's no adequate thing for conditions that target shipments and shipping rates with this system (let alone something for prices). With the previous commit in place and solidusio#6357, we can fully deprecate these modules for Solidus 5. What this does is: If a condition includes any of the modules and defines the `eligible?` method, we emit a deprecation warning telling the implementer to stop including the module and rename their method. That way the `respond_to?` logic from the base class kicks in, and we can remove the awkward API.
1 parent b547049 commit fa69480

18 files changed

+166
-6
lines changed

promotions/app/models/concerns/solidus_promotions/conditions/line_item_level_condition.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
module SolidusPromotions
44
module Conditions
55
module LineItemLevelCondition
6-
def applicable?(promotable)
7-
promotable.is_a?(Spree::LineItem)
6+
def self.included(base)
7+
def base.method_added(method)
8+
if method == :eligible?
9+
Spree.deprecator.warn <<~MSG
10+
Defining `eligible?` on a promotion along with including the `LineItemLevelCondition` module is deprecated.
11+
Rename `eligible?` to `line_item_eligible?` and stop including the `LineItemLevelCondition` module.
12+
MSG
13+
define_method(:applicable?) do |promotable|
14+
promotable.is_a?(Spree::LineItem)
15+
end
16+
end
17+
18+
super
19+
end
820
end
921

1022
def level

promotions/app/models/concerns/solidus_promotions/conditions/order_level_condition.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
module SolidusPromotions
44
module Conditions
55
module OrderLevelCondition
6-
def applicable?(promotable)
7-
promotable.is_a?(Spree::Order)
6+
def self.included(base)
7+
def base.method_added(method)
8+
if method == :eligible?
9+
Spree.deprecator.warn <<~MSG
10+
Defining `eligible?` on a promotion along with including the `OrderLevelCondition` module is deprecated.
11+
Rename `eligible?` to `order_eligible?` and stop including the `OrderLevelCondition` module.
12+
MSG
13+
define_method(:applicable?) do |promotable|
14+
promotable.is_a?(Spree::Order)
15+
end
16+
end
17+
18+
super
19+
end
820
end
921

1022
def level

promotions/app/models/concerns/solidus_promotions/conditions/shipment_level_condition.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
module SolidusPromotions
44
module Conditions
55
module ShipmentLevelCondition
6-
def applicable?(promotable)
7-
promotable.is_a?(Spree::Shipment)
6+
def self.included(base)
7+
def base.method_added(method)
8+
if method == :eligible?
9+
Spree.deprecator.warn <<~MSG
10+
Defining `eligible?` on a promotion along with including the `ShipmentLevelCondition` module is deprecated.
11+
Rename `eligible?` to `shipment_eligible?` and stop including the `ShipmentLevelCondition` module.
12+
MSG
13+
define_method(:applicable?) do |promotable|
14+
promotable.is_a?(Spree::Shipment)
15+
end
16+
end
17+
18+
super
19+
end
820
end
921

1022
def level

promotions/app/models/solidus_promotions/conditions/first_order.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
module SolidusPromotions
44
module Conditions
55
class FirstOrder < Condition
6+
# TODO: Remove in Solidus 5
67
include OrderLevelCondition
8+
79
attr_reader :user, :email
810

911
def order_eligible?(order, options = {})

promotions/app/models/solidus_promotions/conditions/first_repeat_purchase_since.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module SolidusPromotions
44
module Conditions
55
class FirstRepeatPurchaseSince < Condition
6+
# TODO: Remove in Solidus 5
67
include OrderLevelCondition
78

89
preference :days_ago, :integer, default: 365

promotions/app/models/solidus_promotions/conditions/item_total.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Conditions
88
# To add extra operators please override `self.operators_map` or any other helper method.
99
# To customize the error message you can also override `ineligible_message`.
1010
class ItemTotal < Condition
11+
# TODO: Remove in Solidus 5
1112
include OrderLevelCondition
1213

1314
preference :amount, :decimal, default: 100.00

promotions/app/models/solidus_promotions/conditions/line_item_option_value.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module SolidusPromotions
44
module Conditions
55
class LineItemOptionValue < Condition
6+
# TODO: Remove in Solidus 5
67
include LineItemLevelCondition
78

89
preference :eligible_values, :hash

promotions/app/models/solidus_promotions/conditions/line_item_product.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module SolidusPromotions
44
module Conditions
55
# A condition to apply a promotion only to line items with or without a chosen product
66
class LineItemProduct < Condition
7+
# TODO: Remove in Solidus 5
78
include LineItemLevelCondition
89

910
MATCH_POLICIES = %w[include exclude].freeze

promotions/app/models/solidus_promotions/conditions/line_item_taxon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module SolidusPromotions
44
module Conditions
55
class LineItemTaxon < Condition
6+
# TODO: Remove in Solidus 5
67
include LineItemLevelCondition
78

89
has_many :condition_taxons,

promotions/app/models/solidus_promotions/conditions/minimum_quantity.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Conditions
1010
# it to a simple quantity check across the entire order which would be
1111
# better served by an item total condition.
1212
class MinimumQuantity < Condition
13+
# TODO: Remove in Solidus 5
1314
include OrderLevelCondition
1415

1516
validates :preferred_minimum_quantity, numericality: { only_integer: true, greater_than: 0 }

0 commit comments

Comments
 (0)