Class: Spree::Adjustment
- Extended by:
- DisplayMoney
- Defined in:
- app/models/spree/adjustment.rb
Instance Method Summary collapse
- #amount=(amount) ⇒ Object
- #currency ⇒ Object
- #promotion? ⇒ Boolean
-
#update!(target = adjustable) ⇒ Object
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.
Methods included from DisplayMoney
Methods inherited from Base
belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope
Methods included from Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference
Instance Method Details
#amount=(amount) ⇒ Object
78 79 80 |
# File 'app/models/spree/adjustment.rb', line 78 def amount=(amount) self[:amount] = Spree::LocalizedNumber.parse(amount) end |
#currency ⇒ Object
82 83 84 |
# File 'app/models/spree/adjustment.rb', line 82 def currency adjustable ? adjustable.currency : order.currency end |
#promotion? ⇒ Boolean
86 87 88 |
# File 'app/models/spree/adjustment.rb', line 86 def promotion? source_type == 'Spree::PromotionAction' end |
#update!(target = adjustable) ⇒ Object
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.
93 94 95 96 97 98 99 100 101 |
# File 'app/models/spree/adjustment.rb', line 93 def update!(target = adjustable) return amount if closed? || source.blank? amount = source.compute_amount(target) attributes = { amount: amount, updated_at: Time.current } attributes[:eligible] = source.promotion.eligible?(target) if promotion? update_columns(attributes) amount end |