Class: Spree::Adjustment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::Adjustment
- Defined in:
- app/models/spree/adjustment.rb
Instance Method Summary collapse
- #currency ⇒ Object
- #display_amount ⇒ Object
-
#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?.
- #immutable? ⇒ Boolean
- #promotion? ⇒ Boolean
-
#set_eligibility ⇒ Object
Update the boolean eligible attribute which determines which adjustments count towards the order’s adjustment_total.
-
#update!(calculable = nil) ⇒ Object
Update both the eligibility and amount of the adjustment.
Instance Method Details
#currency ⇒ Object
99 100 101 |
# File 'app/models/spree/adjustment.rb', line 99 def currency adjustable ? adjustable.currency : Spree::Config[:currency] end |
#display_amount ⇒ Object
103 104 105 |
# File 'app/models/spree/adjustment.rb', line 103 def display_amount Spree::Money.new(amount, { currency: currency }) end |
#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?
76 77 78 79 |
# File 'app/models/spree/adjustment.rb', line 76 def eligible_for_originator? return true if originator.nil? !originator.respond_to?(:eligible?) || originator.eligible?(source) end |
#immutable? ⇒ Boolean
107 108 109 |
# File 'app/models/spree/adjustment.rb', line 107 def immutable? state != "open" end |
#promotion? ⇒ Boolean
63 64 65 |
# File 'app/models/spree/adjustment.rb', line 63 def promotion? originator_type == 'Spree::PromotionAction' end |
#set_eligibility ⇒ Object
Update the boolean eligible attribute which determines which adjustments count towards the order’s adjustment_total.
69 70 71 72 |
# File 'app/models/spree/adjustment.rb', line 69 def set_eligibility result = mandatory || ((amount != 0 || promotion?) && eligible_for_originator?) update_attribute_without_callbacks(:eligible, result) end |
#update!(calculable = 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.
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
88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/spree/adjustment.rb', line 88 def update!(calculable=nil) return if immutable? # Fix for #3381 # If we attempt to call 'source' before the reload, then source is currently # the order object. After calling a reload, the source is the Shipment. reload calculable = source unless calculable == source originator.update_adjustment(self, calculable) if originator.present? set_eligibility end |