You are here

function commerce_avatax_line_item_new in Drupal Commerce Connector for AvaTax 7.4

Same name and namespace in other branches
  1. 7.5 commerce_avatax.module \commerce_avatax_line_item_new()
  2. 7.3 commerce_avatax.module \commerce_avatax_line_item_new()

Creates a new AvaTax line item populated with the sales tax values.

Parameters

array $sales_tax: A price array used to initialize the value of the line item's unit price.

int $order_id: The ID of the order the line item belongs to.

array $data: An array value to initialize the line item's data array with.

string $type: The name of the line item type being created; defaults to 'avatax'.

Return value

object The avatax line item initialized to the given unit price.

1 call to commerce_avatax_line_item_new()
commerce_avatax_line_item_create in ./commerce_avatax.module
Creates a sales tax line item.

File

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

Code

function commerce_avatax_line_item_new($sales_tax = array(), $order_id = 0, $data = array(), $type = 'avatax') {

  // Ensure a default product line item type.
  if (empty($type)) {
    $type = 'avatax';
  }

  // Create the new line item.
  $line_item = entity_create('commerce_line_item', array(
    'type' => $type,
    'order_id' => $order_id,
    'quantity' => 1,
    'data' => $data,
  ));

  // Populate line item with the sales tax unit price data.
  commerce_avatax_line_item_populate($line_item, $sales_tax);
  return $line_item;
}