4

I have tried the following events for invoice creation observer:

sales_order_invoice_save_after

sales_order_invoice_pay

sales_order_invoice_register

sales_order_invoice_save_commit_after

controller_action_postdispatch_sales_order_invoice_save

and in the observer I am calling:

$invoice = $observer->getEvent()->getInvoice();
$invoice_id = $item->getData('entity_id');

For all of the above events, the entity_id is received as null. Also the observer is called before there is a new entry in the database.

What is the correct event to get invoice id after it is saved?

3
  • Can I know the location of events.xml? Nov 13, 2018 at 4:52
  • scope is kept as global for now
    – GenZ Dev
    Nov 13, 2018 at 5:52
  • 1
    sales_order_invoice_save_commit_after this saved my life.
    – iskorum
    May 17, 2019 at 11:32

1 Answer 1

3

check if it is not typo. using this event sales_order_invoice_register

replace

$invoice = $observer->getEvent()->getInvoice();
$invoice_id = $item->getData('entity_id');

with

$invoice = $observer->getEvent()->getInvoice();
$invoice_id = $invoice->getData('entity_id');
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.