You are here

function commerce_reports_tax_entity_update in Commerce Reporting 7.3

Same name and namespace in other branches
  1. 7.4 modules/tax/commerce_reports_tax.module \commerce_reports_tax_entity_update()

Implements hook_entity_update().

File

modules/tax/commerce_reports_tax.module, line 166

Code

function commerce_reports_tax_entity_update($entity, $type) {
  if ($type == 'commerce_order' && isset($entity->original)) {
    $original = $entity->original;
    $order_status = $entity->status;
    $original_order_status = $original->status;
    $include = in_array($order_status, commerce_reports_tax_order_statuses());
    $included = in_array($original_order_status, commerce_reports_tax_order_statuses());

    // The order changed to a order status we're interested in,
    // we should extract its tax information.
    if (!$included && $include) {
      commerce_reports_tax_order_save($entity);
    }
    elseif ($included && !$include) {
      commerce_reports_tax_order_delete($entity->order_id);
    }
    elseif ($included && $include && $original->commerce_order_total != $entity->commerce_order_total) {
      commerce_reports_tax_order_save($entity, TRUE);
    }
  }
}