You are here

function hook_commerce_product_can_delete in Commerce Core 7

Lets modules prevent the deletion of a particular product.

Before a product can be deleted, other modules are given the chance to say whether or not the action should be allowed. Modules implementing this hook can check for reference data or any other reason to prevent a product from being deleted and return FALSE to prevent the action.

This is an API level hook, so implementations should not display any messages to the user (although logging to the watchdog is fine).

Parameters

$product: The product to be deleted.

Return value

TRUE or FALSE indicating whether or not the given product can be deleted.

See also

commerce_product_reference_commerce_product_can_delete()

1 function implements hook_commerce_product_can_delete()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

commerce_product_reference_commerce_product_can_delete in modules/product_reference/commerce_product_reference.module
Implements hook_commerce_product_can_delete().
1 invocation of hook_commerce_product_can_delete()
commerce_product_can_delete in modules/product/commerce_product.module
Determines whether or not the give product can be deleted.

File

modules/product/commerce_product.api.php, line 158
Hooks provided by the Product module.

Code

function hook_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
    ->entityCondition('entity_type', 'commerce_line_item', '=')
    ->entityCondition('bundle', 'product', '=')
    ->fieldCondition('product', 'product_id', $product->product_id, '=')
    ->count();
  return $query
    ->execute() > 0 ? FALSE : TRUE;
}