You are here

public function TimestampEventSubscriber::onAnyTransition in Commerce Core 8.2

Sets the order's completed timestamp.

Parameters

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

File

modules/order/src/EventSubscriber/TimestampEventSubscriber.php, line 59

Class

TimestampEventSubscriber

Namespace

Drupal\commerce_order\EventSubscriber

Code

public function onAnyTransition(WorkflowTransitionEvent $event) {

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $event
    ->getEntity();
  $to_state_id = $event
    ->getTransition()
    ->getToState()
    ->getId();
  if ($to_state_id == 'completed' && empty($order
    ->getCompletedTime())) {
    $order
      ->setCompletedTime($this->time
      ->getRequestTime());
  }
}