function commerce_avatax_add_line_item in Drupal Commerce Connector for AvaTax 7.5
Create, add an AvaTax line item to an order, and saves the order.
Parameters
EntityDrupalWrapper $order_wrapper: The wrapped order entity.
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.
Return value
object The newly created tax line item wrapper.
1 call to commerce_avatax_add_line_item()
- commerce_avatax_calculate_tax in ./
commerce_avatax.module - Performs Tax calculation for a given order.
File
- ./
commerce_avatax.module, line 534 - AvaTax service integration from Avalara, Inc.
Code
function commerce_avatax_add_line_item(EntityDrupalWrapper $order_wrapper, $tax_price, $tax_type) {
// Create the new line item.
$line_item = entity_create('commerce_line_item', array(
'type' => 'avatax',
'order_id' => $order_wrapper
->getIdentifier(),
'quantity' => 1,
));
// Sets the unit price.
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
commerce_avatax_set_price_component($line_item_wrapper, $tax_price, $tax_type);
// Save the incoming line item now so we get its ID.
commerce_line_item_save($line_item);
// Add it to the order's line item reference value.
$order_wrapper->commerce_line_items[] = $line_item;
// Return the line item.
return $line_item_wrapper;
}