You are here

function commerce_file_commerce_order_delete in Commerce File 7

Implements hook_commerce_order_delete().

  • Remove license line item references on order delete. The line item will not get deleted by commerce_line_item_field_attach_delete() if another entity is referencing the line item, ie licenses. Here we are just removing the line item references on the licenses so the line item entity will be orphaned.

File

./commerce_file.module, line 966
Provides integration of file licenses with Commerce

Code

function commerce_file_commerce_order_delete($order) {
  $line_item_field_items = field_get_items('commerce_order', $order, 'commerce_line_items');
  if (empty($line_item_field_items)) {
    return;
  }
  $line_item_ids = array();
  foreach ($line_item_field_items as $line_item_field_item) {
    $line_item_ids[] = $line_item_field_item['line_item_id'];
  }
  $line_items = commerce_line_item_load_multiple($line_item_ids);
  foreach ($line_items as $line_item_id => $line_item) {
    _commerce_file_license_line_item_delete_references($line_item);
  }
}