You are here

public static function Order::postDelete in Ubercart 8.4

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

uc_order/src/Entity/Order.php, line 167

Class

Order
Defines the order entity class.

Namespace

Drupal\uc_order\Entity

Code

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

  // Delete data from the appropriate Ubercart order tables.
  $ids = array_keys($orders);
  $result = \Drupal::entityQuery('uc_order_product')
    ->condition('order_id', $ids, 'IN')
    ->execute();
  if (!empty($result)) {
    entity_delete_multiple('uc_order_product', array_keys($result));
  }
  \Drupal::database()
    ->delete('uc_order_comments')
    ->condition('order_id', $ids, 'IN')
    ->execute();
  \Drupal::database()
    ->delete('uc_order_admin_comments')
    ->condition('order_id', $ids, 'IN')
    ->execute();
  \Drupal::database()
    ->delete('uc_order_log')
    ->condition('order_id', $ids, 'IN')
    ->execute();
  foreach ($orders as $order_id => $order) {

    // Delete line items for the order.
    uc_order_delete_line_item($order_id, TRUE);

    // Log the action in the database.
    \Drupal::logger('uc_order')
      ->notice('Order @order_id deleted by user @uid.', [
      '@order_id' => $order_id,
      '@uid' => \Drupal::currentUser()
        ->id(),
    ]);

    /* rules_invoke_event('uc_order_delete', $order); */
    $event = new OrderDeletedEvent($order);
    \Drupal::service('event_dispatcher')
      ->dispatch($event::EVENT_NAME, $event);
  }
}