function commerce_avatax_set_price_component in Drupal Commerce Connector for AvaTax 7.5
Sets a tax price component to the provided line item.
Parameters
$line_item_wrapper: An entity_metadata_wrapper() for the line item whose unit price should be used in the vat calculation.
array $tax_price: A price array used to initialize the value of the line item's unit price.
string $tax_type: A string determining the price component to add.
2 calls to commerce_avatax_set_price_component()
- commerce_avatax_add_line_item in ./
commerce_avatax.module - Create, add an AvaTax line item to an order, and saves the order.
- commerce_avatax_set_existing_line_item_price in ./
commerce_avatax.module - Updates the unit price of the Avatax line item if it exists.
File
- ./
commerce_avatax.module, line 566 - AvaTax service integration from Avalara, Inc.
Code
function commerce_avatax_set_price_component($line_item_wrapper, $tax_price, $tax_type) {
$types_mapping = array(
'sales_tax' => array(
'line_item_label' => t('Sales Tax'),
'price_component' => 'avatax_sales_tax',
),
'vat' => array(
'line_item_label' => t('VAT'),
'price_component' => 'avatax_vat',
),
);
if (isset($types_mapping[$tax_type])) {
$line_item_label = $types_mapping[$tax_type]['line_item_label'];
$price_component = $types_mapping[$tax_type]['price_component'];
}
else {
// Defaults to Sales Tax.
$line_item_label = t('Sales Tax');
$price_component = $types_mapping['sales_tax']['price_component'];
}
$line_item_wrapper->line_item_label = $line_item_label;
$line_item_wrapper->commerce_unit_price->amount = $tax_price['amount'];
$line_item_wrapper->commerce_unit_price->currency_code = $tax_price['currency_code'];
// Reset the data array of the line item total field to only include a
// base price component, set the currency code from the order.
$base_price = array(
'amount' => 0,
'currency_code' => $tax_price['currency_code'],
'data' => array(),
);
$line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($base_price, $price_component, $tax_price, TRUE);
}