You are here

function commerce_avatax_delete_tax_line_items in Drupal Commerce Connector for AvaTax 7.5

Deletes AvaTax line items of an order.

Parameters

EntityDrupalWrapper $order_wrapper: The wrapped order entity.

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

1 call to commerce_avatax_delete_tax_line_items()
commerce_avatax_calculate_tax in ./commerce_avatax.module
Performs Tax calculation for a given order.

File

./commerce_avatax.module, line 637
AvaTax service integration from Avalara, Inc.

Code

function commerce_avatax_delete_tax_line_items(EntityDrupalWrapper $order_wrapper, $skip_save = FALSE) {
  $line_items_to_delete = array();
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {

    // Skip non Avatax line items.
    if (!$line_item_wrapper
      ->value() || $line_item_wrapper
      ->getBundle() != 'avatax') {
      continue;
    }
    $line_items_to_delete[] = $line_item_wrapper->line_item_id
      ->value();
    $order_wrapper->commerce_line_items
      ->offsetUnset($delta);
  }

  // If we found line items to delete.
  if (!empty($line_items_to_delete)) {

    // First save the order to update the line item reference field value.
    if (!$skip_save) {
      $order_wrapper
        ->save();
    }

    // Delete the line items on shutdown, to prevent the line item controller
    // delete method to fire and save the order for us.
    drupal_register_shutdown_function('commerce_line_item_delete_multiple', $line_items_to_delete);
  }
}