You are here

function commerce_avatax_line_item_create in Drupal Commerce Connector for AvaTax 7.4

Same name and namespace in other branches
  1. 7.3 commerce_avatax.module \commerce_avatax_line_item_create()

Creates a sales tax line item.

Parameters

array $sales_tax: A price array used to establish the base unit price for the AvaTax.

int $order_id: If available, the order to which the AvaTax line item will belong.

Return value

object The sales tax line item.

2 calls to commerce_avatax_line_item_create()
commerce_avatax_calculate_sales_tax in ./commerce_avatax.module
Calculate sales tax using regular web site checkout.
commerce_avatax_manual_calculate_sales_tax in ./commerce_avatax.module
Calculate sales tax for manual order entry.

File

./commerce_avatax.module, line 194
Calculate Sales Tax using AvaTax service from Avalara, Inc.

Code

function commerce_avatax_line_item_create($sales_tax = array(), $order_id = 0) {
  $avatax_service = commerce_avatax_service_load();

  // Create the new line item for AvaTax.
  $line_item = commerce_avatax_line_item_new($sales_tax, $order_id);

  // Set the price component of the unit price if it hasn't already been done.
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $data = $line_item_wrapper->commerce_unit_price->data
    ->value();
  if (empty($data['components'])) {
    $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($line_item_wrapper->commerce_unit_price
      ->value(), $avatax_service['price_component'], $line_item_wrapper->commerce_unit_price
      ->value(), TRUE, FALSE);
  }
  return $line_item;
}