@@ -163,8 +163,24 @@ def self.find_by_param!(value)
163163 delegate :name , to : :bill_address , prefix : true , allow_nil : true
164164 alias_method :billing_name , :bill_address_name
165165
166- class_attribute :line_item_comparison_hooks
167- self . line_item_comparison_hooks = Set . new
166+ delegate :line_item_comparison_hooks , to : :class
167+ class << self
168+ def line_item_comparison_hooks = ( value )
169+ Spree ::Config . line_item_comparison_hooks = value . to_a
170+ end
171+ line_item_hooks_deprecation_msg = "Use Spree::Config.line_item_comparison_hooks instead."
172+ deprecate :line_item_comparison_hooks= => line_item_hooks_deprecation_msg , :deprecator => Spree . deprecator
173+
174+ def line_item_comparison_hooks
175+ Spree ::Config . line_item_comparison_hooks
176+ end
177+ deprecate line_item_comparison_hooks : line_item_hooks_deprecation_msg , deprecator : Spree . deprecator
178+
179+ def register_line_item_comparison_hook ( hook )
180+ Spree ::Config . line_item_comparison_hooks << hook
181+ end
182+ deprecate register_line_item_comparison_hook : line_item_hooks_deprecation_msg , deprecator : Spree . deprecator
183+ end
168184
169185 scope :created_between , -> ( start_date , end_date ) { where ( created_at : start_date ..end_date ) }
170186 scope :completed_between , -> ( start_date , end_date ) { where ( completed_at : start_date ..end_date ) }
@@ -198,12 +214,6 @@ def self.not_canceled
198214 where . not ( state : 'canceled' )
199215 end
200216
201- # Use this method in other gems that wish to register their own custom logic
202- # that should be called when determining if two line items are equal.
203- def self . register_line_item_comparison_hook ( hook )
204- line_item_comparison_hooks . add ( hook )
205- end
206-
207217 # For compatiblity with Calculator::PriceSack
208218 def amount
209219 line_items . sum ( &:amount )
@@ -356,7 +366,7 @@ def find_line_item_by_variant(variant, options = {})
356366 def line_item_options_match ( line_item , options )
357367 return true unless options
358368
359- line_item_comparison_hooks . all? { |hook |
369+ Spree :: Config . line_item_comparison_hooks . all? { |hook |
360370 send ( hook , line_item , options )
361371 }
362372 end
0 commit comments