Class: Spree::OrderTaxation

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/order_taxation.rb

Overview

Relatively simple class used to apply a Tax::OrderTax to a Order.

This class will create or update adjustments on the taxed items and remove any now inapplicable tax adjustments from the order.

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ Spree::OrderTaxation

Create a new order taxation.

Parameters:



14
15
16
# File 'app/models/spree/order_taxation.rb', line 14

def initialize(order)
  @order = order
end

Instance Method Details

#apply(taxes) ⇒ void

This method returns an undefined value.

Apply taxes to the order.

This method will create or update adjustments on the order and all line items and shipments in the order to reflect the appropriate taxes passed in. It will also remove any now inapplicable tax adjustments.

Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/spree/order_taxation.rb', line 26

def apply(taxes)
  update_adjustments(@order, taxes.order_taxes) if taxes.order_taxes

  @order.line_items.each do |item|
    taxed_items = taxes.line_item_taxes.select { |element| element.item_id == item.id }
    update_adjustments(item, taxed_items)
  end

  @order.shipments.each do |item|
    taxed_items = taxes.shipment_taxes.select { |element| element.item_id == item.id }
    update_adjustments(item, taxed_items)
  end
end