Class: Spree::ItemTotal
- Inherits:
-
Object
- Object
- Spree::ItemTotal
- Defined in:
- app/models/spree/item_total.rb
Instance Method Summary collapse
-
#initialize(item) ⇒ ItemTotal
constructor
A new instance of ItemTotal.
- #recalculate! ⇒ Object
Constructor Details
#initialize(item) ⇒ ItemTotal
Returns a new instance of ItemTotal.
4 5 6 |
# File 'app/models/spree/item_total.rb', line 4 def initialize(item) @item = item end |
Instance Method Details
#recalculate! ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/spree/item_total.rb', line 8 def recalculate! tax_adjustments = item.adjustments.select do |adjustment| adjustment.tax? && !adjustment.marked_for_destruction? end # Included tax adjustments are those which are included in the price. # These ones should not affect the eventual total price. # # Additional tax adjustments are the opposite, affecting the final total. item.included_tax_total = tax_adjustments.select(&:included?).sum(&:amount) item.additional_tax_total = tax_adjustments.reject(&:included?).sum(&:amount) item.adjustment_total = item.adjustments.reject { |adjustment| adjustment.marked_for_destruction? || adjustment.included? }.sum(&:amount) end |