You are here

function commerce_product_reference_commerce_product_can_delete in Commerce Core 7

Implements hook_commerce_product_can_delete().

File

modules/product_reference/commerce_product_reference.module, line 1486
Defines a field type for referencing products from other entities.

Code

function commerce_product_reference_commerce_product_can_delete($product) {

  // Use EntityFieldQuery to look for line items referencing this product and do
  // not allow the delete to occur if one exists.
  $query = new EntityFieldQuery();
  $query
    ->addTag('commerce_product_reference_commerce_product_can_delete')
    ->entityCondition('entity_type', 'commerce_line_item', '=')
    ->entityCondition('bundle', commerce_product_line_item_types(), 'IN')
    ->fieldCondition('commerce_product', 'product_id', $product->product_id, '=')
    ->count();
  return $query
    ->execute() == 0;
}