You are here

public function InvoiceSubscriber::onPayPreTransition in Commerce Invoice 8.2

Sets the total_paid field when an invoice is paid.

Parameters

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

File

src/EventSubscriber/InvoiceSubscriber.php, line 27

Class

InvoiceSubscriber

Namespace

Drupal\commerce_invoice\EventSubscriber

Code

public function onPayPreTransition(WorkflowTransitionEvent $event) {

  /** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
  $invoice = $event
    ->getEntity();
  if (!$invoice
    ->isPaid()) {
    $invoice
      ->setTotalPaid($invoice
      ->getTotalPrice());
  }
}