You are here

public function Order::postSave in Ubercart 8.4

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides ContentEntityBase::postSave

File

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

Class

Order
Defines the order entity class.

Namespace

Drupal\uc_order\Entity

Code

public function postSave(EntityStorageInterface $storage, $update = TRUE) {
  parent::postSave($storage, $update);
  foreach ($this->products as $product) {
    \Drupal::moduleHandler()
      ->alter('uc_order_product', $product, $this);
    uc_order_product_save($this
      ->id(), $product);
  }

  // Record a log entry if the order status has changed.
  if ($update && $this
    ->getStatusId() != $this->original
    ->getStatusId()) {
    $this
      ->logChanges([
      (string) t('Order status') => [
        'old' => $this->original
          ->getStatus()
          ->getName(),
        'new' => $this
          ->getStatus()
          ->getName(),
      ],
    ]);

    /* rules_invoke_event('uc_order_status_update', $this->original, $this); */
    $event = new OrderStatusUpdateEvent($this->original, $this);
    \Drupal::service('event_dispatcher')
      ->dispatch($event::EVENT_NAME, $event);
  }
}