function commerce_pricelist_entity_delete in Commerce Pricelist 8.2
Same name and namespace in other branches
- 8 commerce_pricelist.module \commerce_pricelist_entity_delete()
- 7 commerce_pricelist.module \commerce_pricelist_entity_delete()
Implements hook_entity_delete().
File
- ./
commerce_pricelist.module, line 62 - Allows defining prices for specific stores, customers, quantities.
Code
function commerce_pricelist_entity_delete(EntityInterface $entity) {
if ($entity
->getEntityType()
->entityClassImplements(PurchasableEntityInterface::class)) {
// A purchasable entity was deleted. Delete all of its price list items.
$price_list_item_storage = \Drupal::entityTypeManager()
->getStorage('commerce_pricelist_item');
$query = $price_list_item_storage
->getQuery();
$query
->condition('type', $entity
->getEntityTypeId());
$query
->condition('purchasable_entity', $entity
->id());
$result = $query
->execute();
if (!empty($result)) {
// @todo This can crash due to there potentially being thousands of items.
$price_list_items = $price_list_item_storage
->loadMultiple($result);
$price_list_item_storage
->delete($price_list_items);
}
}
}