You are here

function commerce_wishlist_entity_delete in Commerce Wishlist 8.3

Same name and namespace in other branches
  1. 7.2 commerce_wishlist.module \commerce_wishlist_entity_delete()

Implements hook_entity_delete().

Queues wishlist items for deletion when a purchasable entity is deleted.

File

./commerce_wishlist.module, line 369
Defines the Wishlist entity and associated features.

Code

function commerce_wishlist_entity_delete(EntityInterface $entity) {
  if ($entity
    ->getEntityType()
    ->entityClassImplements(PurchasableEntityInterface::class)) {
    $wishlist_item_storage = \Drupal::entityTypeManager()
      ->getStorage('commerce_wishlist_item');
    $query = $wishlist_item_storage
      ->getQuery()
      ->condition('type', $entity
      ->getEntityTypeId())
      ->condition('purchasable_entity', $entity
      ->id());
    $result = $query
      ->execute();
    $queue = \Drupal::queue('commerce_wishlist_item_delete');
    foreach (array_chunk($result, 25) as $ids) {
      $queue
        ->createItem([
        'ids' => $ids,
      ]);
    }
  }
}