You are here

function commerce_option_entity_delete in Commerce Product Option 7.2

Same name and namespace in other branches
  1. 7 commerce_option.module \commerce_option_entity_delete()

Implements hook_entity_delete().

Delete all options, when the associated line item is deleted.

File

./commerce_option.module, line 435

Code

function commerce_option_entity_delete($entity, $type) {
  if ($type != 'commerce_line_item') {
    return;
  }
  $options = commerce_option_load_by_line_item($entity->line_item_id);
  if (empty($options)) {
    return;
  }

  // Delete data in field tables
  foreach ($options as $option) {
    field_attach_delete('commerce_option', $option);
  }

  // Delete entries from commerce_option table.
  entity_delete_multiple('commerce_option', array_keys($options));
}