function commerce_reports_tax_entity_update in Commerce Reporting 7.4
Same name and namespace in other branches
- 7.3 modules/tax/commerce_reports_tax.module \commerce_reports_tax_entity_update()
Implements hook_entity_update().
File
- modules/
tax/ commerce_reports_tax.module, line 165 - Module file for Commerce Reports Tax.
Code
function commerce_reports_tax_entity_update($entity, $type) {
if ($type == 'commerce_order' && isset($entity->original)) {
// Mark original entity for easy reference.
$original = $entity->original;
// Check the updated status against statuses in settings.
$order_current_status = in_array($entity->status, variable_get('commerce_reports_tax_order_statuses', array(
'pending',
'processing',
'completed',
)));
// Check the original status, so we know if we need to remove last record.
$order_previous_status = in_array($original->status, variable_get('commerce_reports_tax_order_statuses', array(
'pending',
'processing',
'completed',
)));
// The order changed to a order status we're interested in, but did not
// previously have a watched status. Create a new record.
if ($order_current_status && !$order_previous_status) {
commerce_reports_tax_order_save($entity);
}
elseif (!$order_current_status && $order_previous_status) {
commerce_reports_tax_order_delete($entity->order_id);
}
elseif ($order_current_status && $order_previous_status && $original->commerce_order_total != $entity->commerce_order_total) {
commerce_reports_tax_order_save($entity);
}
}
}