Class: Spree::TaxCalculator::Default

Inherits:
Object
  • Object
show all
Includes:
Spree::Tax::TaxHelpers
Defined in:
core/app/models/spree/tax_calculator/default.rb

Overview

Default implementation for tax calculations. Will go through all line items and shipments and calculate their tax based on tax rates in the DB.

The class used for tax calculation is configurable, so that the calculation can easily be pushed to third-party services. Users looking to provide their own calculator should adhere to the API of this class.

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ Spree::TaxCalculator::Default

Create a new tax calculator.

Parameters:



18
19
20
# File 'core/app/models/spree/tax_calculator/default.rb', line 18

def initialize(order)
  @order = order
end

Instance Method Details

#calculateSpree::Tax::OrderTax

Calculate taxes for an order.

Returns:



25
26
27
28
29
30
31
# File 'core/app/models/spree/tax_calculator/default.rb', line 25

def calculate
  Spree::Tax::OrderTax.new(
    order_id: order.id,
    line_item_taxes: line_item_rates,
    shipment_taxes: shipment_rates
  )
end