Skip to content

Commit

Permalink
Merge pull request #403 from helloextend/feat/MINT-1744-allow-compati…
Browse files Browse the repository at this point in the history
…bility-with-authorize-plugin

feat: [MINT-1744] use sales_order_invoice_save_after event for invoice observer
  • Loading branch information
jm-extend authored Feb 6, 2024
2 parents d4b42ce + 3ffd5bf commit 8b52b2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Observer/ContractCreate/InvoiceObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<event name="sales_model_service_quote_submit_success">
<observer name="extend_warranty_create_order_observer" instance="Extend\Warranty\Observer\CreateOrder"/>
</event>
<event name="sales_order_invoice_pay">
<event name="sales_order_invoice_save_after">
<observer name="extend_warranty_create_warranty_invoice_after_observer"
instance="Extend\Warranty\Observer\ContractCreate\InvoiceObserver"/>
</event>
Expand Down

0 comments on commit 8b52b2b

Please sign in to comment.