You are here

function commerce_avatax_add_avatax_line_item in Drupal Commerce Connector for AvaTax 7.3

Same name and namespace in other branches
  1. 7.4 commerce_avatax.module \commerce_avatax_add_avatax_line_item()

Adds a avatax line item to an order, and saves the order.

Parameters

$line_item: An unsaved tax saas line item that should be added to the order.

$order: The order to add the tax saas line item to.

$skip_save: Boolean indicating whether or not to skip saving the order in this function.

Return value

The saved tax saas line item object or FALSE on failure.

1 call to commerce_avatax_add_avatax_line_item()
commerce_avatax_calculate_sales_tax in ./commerce_avatax.module
Calculate sales tax using regular web site checkout.

File

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

Code

function commerce_avatax_add_avatax_line_item($line_item, $order) {

  // Do not proceed without a valid order.
  if (empty($order)) {
    return FALSE;
  }

  // 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 = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper->commerce_line_items[] = $line_item;
  commerce_order_calculate_total($order);
  commerce_order_save($order);
}