You are here

function commerce_tax_type_calculate_rates in Commerce Core 7

Calculates taxes of a particular type by invoking any components that match the tax type.

Parameters

$tax_type: The tax type object whose rates should be calculated.

$line_item: The line item to which the taxes should be applied.

1 call to commerce_tax_type_calculate_rates()
commerce_tax_calculate_by_type in modules/tax/commerce_tax.rules.inc
Rules action: checks for the application of each tax rate of a certain type.

File

modules/tax/commerce_tax.module, line 227
Defines tax rates and Rules integration for configuring tax rules for applicability and display.

Code

function commerce_tax_type_calculate_rates($tax_type, $line_item) {

  // Prepare an array of rules components to load.
  $component_names = array();

  // Loop over each tax rate in search of matching components.
  foreach (commerce_tax_rates() as $name => $tax_rate) {

    // If the current rate matches the type and specifies a default component...
    if ($tax_rate['type'] == $tax_type['name'] && !empty($tax_rate['rules_component'])) {
      $component_names[] = $tax_rate['rules_component'];
    }
  }

  // Load and invoke the tax rules components.
  if (!empty($component_names)) {
    foreach (rules_config_load_multiple($component_names) as $component_name => $component) {
      rules_invoke_component($component_name, $line_item);
    }
  }

  // Allow modules handling tax application on their own to apply rates of the
  // current type as well.
  module_invoke_all('commerce_tax_type_calculate_rates', $tax_type, $line_item);
}