Class: Spree::Adjustment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::Adjustment
- Defined in:
- app/models/spree/adjustment.rb
Instance Method Summary collapse
-
#eligible_for_originator? ⇒ Boolean
Allow originator of the adjustment to perform an additional eligibility of the adjustment Should return true if originator is absent or doesn’t implement eligible?.
-
#set_eligibility ⇒ Object
Update the boolean eligible attribute which deterimes which adjustments count towards the order’s adjustment_total.
-
#update!(src = nil) ⇒ Object
Update both the eligibility and amount of the adjustment.
Instance Method Details
#eligible_for_originator? ⇒ Boolean
Allow originator of the adjustment to perform an additional eligibility of the adjustment Should return true if originator is absent or doesn’t implement eligible?
53 54 55 56 |
# File 'app/models/spree/adjustment.rb', line 53 def eligible_for_originator? return true if originator.nil? !originator.respond_to?(:eligible?) || originator.eligible?(source) end |
#set_eligibility ⇒ Object
Update the boolean eligible attribute which deterimes which adjustments count towards the order’s adjustment_total.
45 46 47 48 49 |
# File 'app/models/spree/adjustment.rb', line 45 def set_eligibility update_attribute_without_callbacks(:eligible, mandatory || (amount != 0 && eligible_for_originator?)) end |
#update!(src = nil) ⇒ Object
Update both the eligibility and amount of the adjustment. Adjustments delegate updating of amount to their Originator when present, but only if locked
is false. Adjustments that are locked
will never change their amount. The new adjustment amount will be set by by the originator
and is not automatically saved. This makes it save to use this method in an after_save hook for other models without causing an infinite recursion problem.
order#update_adjustments passes self as the src, this is so calculations can be performed on the current values. If we used source it would load the old record from db for the association
65 66 67 68 69 70 71 72 |
# File 'app/models/spree/adjustment.rb', line 65 def update!(src = nil) src ||= source return if locked? if originator.present? originator.update_adjustment(self, src) end set_eligibility end |