Skip to content
Snippets Groups Projects

Issue #3198668: Order onPaid event called twice

2 files
+ 12
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -4,6 +4,7 @@ namespace Drupal\commerce_invoice\EventSubscriber;
use Drupal\state_machine\Event\WorkflowTransitionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\commerce_order\Entity\OrderInterface;
class InvoiceSubscriber implements EventSubscriberInterface {
@@ -41,9 +42,11 @@ class InvoiceSubscriber implements EventSubscriberInterface {
public function onPayPostTransition(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
$invoice = $event->getEntity();
$orders_field = $invoice->get('orders');
// When an invoice is paid, we need to mark the referenced orders as paid.
foreach ($invoice->getOrders() as $order) {
if ($order->isPaid()) {
foreach ($orders_field as $item) {
$order = $item->entity;
if (!$order instanceof OrderInterface || $order->isPaid()) {
continue;
}
$order->setTotalPaid($order->getTotalPrice());
Loading