diff --git a/Observer/ContractCreate/InvoiceObserver.php b/Observer/ContractCreate/InvoiceObserver.php index 085a5b22..30cb03ae 100644 --- a/Observer/ContractCreate/InvoiceObserver.php +++ b/Observer/ContractCreate/InvoiceObserver.php @@ -71,6 +71,16 @@ public function execute(Observer $observer) { $event = $observer->getEvent(); $invoice = $event->getInvoice(); + + /** + * Ideally we would respond to 'sales_order_invoice_pay', but there are some merchants which have plugins + * that create an invoice payment prior to the order existing in the database. This requires us to listen to + * 'sales_order_invoice_save_after' and check if the invoice was paid before we continue. + */ + if (!$invoice->wasPayCalled()) { + return; + } + $order = $invoice->getOrder(); $storeId = $order->getStoreId(); diff --git a/etc/events.xml b/etc/events.xml index 641119fb..3ac4378e 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -22,7 +22,7 @@ - +