You are here

public function OrderEventSubscriber::onOrderPostTransition in Commerce Core 8.2

Creates a log on order state update.

Parameters

\Drupal\state_machine\Event\WorkflowTransitionEvent $event: The transition event.

File

modules/log/src/EventSubscriber/OrderEventSubscriber.php, line 58

Class

OrderEventSubscriber

Namespace

Drupal\commerce_log\EventSubscriber

Code

public function onOrderPostTransition(WorkflowTransitionEvent $event) {
  $transition = $event
    ->getTransition();

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $event
    ->getEntity();
  $original_state_id = $order
    ->getState()
    ->getOriginalId();
  $original_state = $event
    ->getWorkflow()
    ->getState($original_state_id);
  $this->logStorage
    ->generate($order, 'order_state_updated', [
    'transition_label' => $transition
      ->getLabel(),
    'from_state' => $original_state ? $original_state
      ->getLabel() : $original_state_id,
    'to_state' => $order
      ->getState()
      ->getLabel(),
  ])
    ->save();
}