Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [MINT-1744] use sales_order_invoice_save_after event for invoice observer #403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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