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?

  • Can I know the location of events.xml? – Ramkishan Suthar Nov 13 '18 at 4:52
  • scope is kept as global for now – Sufyan Khot Nov 13 '18 at 5:52
  • sales_order_invoice_save_commit_after this saved my life. – iskorum May 17 at 11:32
2

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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