Class: Spree::Adjustment
- Defined in:
- app/models/spree/adjustment.rb
Instance Method Summary collapse
- #closed? ⇒ Boolean
- #currency ⇒ Object
- #display_amount ⇒ Object
- #promotion? ⇒ Boolean
-
#update!(target = nil) ⇒ Object
Recalculate amount given a target e.g.
Methods inherited from Base
Methods included from Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#closed? ⇒ Boolean
66 67 68 |
# File 'app/models/spree/adjustment.rb', line 66 def closed? state == "closed" end |
#currency ⇒ Object
70 71 72 |
# File 'app/models/spree/adjustment.rb', line 70 def currency adjustable ? adjustable.currency : Spree::Config[:currency] end |
#display_amount ⇒ Object
74 75 76 |
# File 'app/models/spree/adjustment.rb', line 74 def display_amount Spree::Money.new(amount, { currency: currency }) end |
#promotion? ⇒ Boolean
78 79 80 |
# File 'app/models/spree/adjustment.rb', line 78 def promotion? source.class < Spree::PromotionAction end |
#update!(target = nil) ⇒ Object
Recalculate amount given a target e.g. Order, Shipment, LineItem
Passing a target here would always be recommended as it would avoid hitting the database again and would ensure you’re compute values over the specific object amount passed here.
Noop if the adjustment is locked.
If the adjustment has no source, do not attempt to re-calculate the amount. Chances are likely that this was a manually created adjustment in the admin backend.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/spree/adjustment.rb', line 92 def update!(target = nil) return amount if closed? if source.present? amount = source.compute_amount(target || adjustable) self.update_columns( amount: amount, updated_at: Time.now, ) if promotion? self.update_column(:eligible, source.promotion.eligible?(adjustable)) end end amount end |