You are here

public static function Promotion::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/promotion/src/Entity/Promotion.php, line 661

Class

Promotion
Defines the promotion entity class.

Namespace

Drupal\commerce_promotion\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $entities) {

  // Delete the linked coupons and usage records.
  $coupons = [];
  foreach ($entities as $entity) {
    foreach ($entity
      ->getCoupons() as $coupon) {
      $coupons[] = $coupon;
    }
  }

  /** @var \Drupal\commerce_promotion\CouponStorageInterface $coupon_storage */
  $coupon_storage = \Drupal::service('entity_type.manager')
    ->getStorage('commerce_promotion_coupon');
  $coupon_storage
    ->delete($coupons);

  /** @var \Drupal\commerce_promotion\PromotionUsageInterface $usage */
  $usage = \Drupal::service('commerce_promotion.usage');
  $usage
    ->delete($entities);
}