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:



12
13
14
# File 'app/models/spree/order_taxation.rb', line 12

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 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:



24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/spree/order_taxation.rb', line 24

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

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