You are here

function commerce_avatax_delete_avatax_transaction in Drupal Commerce Connector for AvaTax 7.4

Deletes AvaTax line items on an order.

Parameters

object $order: The order object to delete the AvaTax line items from.

2 calls to commerce_avatax_delete_avatax_transaction()
commerce_avatax_add_avatax_line_item in ./commerce_avatax.module
Adds an AvaTax line item to an order, and saves the order.
_commerce_avatax_update in ./commerce_avatax.rules.inc
Send Commit/Cancel operation to AvaTax.

File

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

Code

function commerce_avatax_delete_avatax_transaction($order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

  // When deleting more than one line item, metadata_wrapper will give problems
  // if deleting while looping through the line items. So first remove from
  // order and then delete the line items.
  $line_item_ids = array();
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {

    // If this line item is an avatax line item...
    if ($line_item_wrapper->type
      ->value() == 'avatax') {

      // Store its ID for later deletion and remove the reference from the line
      // item reference field.
      $line_item_ids[] = $line_item_wrapper->line_item_id
        ->value();
      $order_wrapper->commerce_line_items
        ->offsetUnset($delta);
    }
  }

  // If we found any AvaTax line items.
  if (!empty($line_item_ids)) {

    // Then delete the line items.
    commerce_line_item_delete_multiple($line_item_ids);
  }
}