You are here

public static function ProductVariation::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/product/src/Entity/ProductVariation.php, line 401

Class

ProductVariation
Defines the product variation entity class.

Namespace

Drupal\commerce_product\Entity

Code

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

  /** @var \Drupal\commerce_product\Entity\ProductVariationInterface[] $entities */
  foreach ($entities as $variation) {

    // Remove the reference from the parent product.
    $product = $variation
      ->getProduct();
    if ($product && $product
      ->hasVariation($variation)) {
      $product
        ->removeVariation($variation);
      $product
        ->save();
    }
  }
}