public static function Order::postDelete in Commerce Core 8.2
Acts on deleted entities before the delete hook is invoked.
Used after the entities are deleted but before invoking the delete hook.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.
Overrides EntityBase::postDelete
File
- modules/
order/ src/ Entity/ Order.php, line 720
Class
- Order
- Defines the order entity class.
Namespace
Drupal\commerce_order\EntityCode
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
// Delete the order items of a deleted order.
$order_items = [];
/** @var \Drupal\commerce_order\Entity\OrderInterface $entity */
foreach ($entities as $entity) {
foreach ($entity
->getItems() as $order_item) {
$order_items[$order_item
->id()] = $order_item;
}
}
/** @var \Drupal\commerce_order\OrderItemStorageInterface $order_item_storage */
$order_item_storage = \Drupal::service('entity_type.manager')
->getStorage('commerce_order_item');
$order_item_storage
->delete($order_items);
}