public function InvoiceSubscriber::onPayPostTransition in Commerce Invoice 8.2
Mark the orders as paid when an invoice is paid.
Parameters
\Drupal\state_machine\Event\WorkflowTransitionEvent $event: The transition event.
File
- src/
EventSubscriber/ InvoiceSubscriber.php, line 41
Class
Namespace
Drupal\commerce_invoice\EventSubscriberCode
public function onPayPostTransition(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
$invoice = $event
->getEntity();
// When an invoice is paid, we need to mark the referenced orders as paid.
foreach ($invoice
->getOrders() as $order) {
if ($order
->isPaid()) {
continue;
}
$order
->setTotalPaid($order
->getTotalPrice());
$order
->save();
}
}