You are here

function commerce_tax_rate_calculate in Commerce Core 7

Calculates a price array for the tax on the unit price of a line item.

Parameters

$tax_rate: The tax rate array for the tax to calculate.

$line_item_wrapper: An entity_metadata_wrapper() for the line item whose unit price should be used in the tax calculation.

Return value

The tax price array or FALSE if the tax is already applied.

2 string references to 'commerce_tax_rate_calculate'
commerce_tax_rates in modules/tax/commerce_tax.module
Returns an array of tax rate objects keyed by name.
commerce_tax_ui_tax_rate_new in modules/tax/commerce_tax_ui.module
Returns an initialized tax rate array.

File

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

Code

function commerce_tax_rate_calculate($tax_rate, $line_item_wrapper) {

  // By default, do not duplicate a tax that's already on the line item.
  if (!is_null($line_item_wrapper->commerce_unit_price
    ->value()) && !commerce_price_component_load($line_item_wrapper->commerce_unit_price
    ->value(), $tax_rate['price_component'])) {

    // Calculate the tax amount.
    $amount = $line_item_wrapper->commerce_unit_price->amount
      ->value() * $tax_rate['rate'];
    return array(
      'amount' => commerce_tax_rate_round_amount($tax_rate, $amount),
      'currency_code' => $line_item_wrapper->commerce_unit_price->currency_code
        ->value(),
      'data' => array(
        'tax_rate' => $tax_rate,
      ),
    );
  }
  return FALSE;
}