In my Magento 1.9 installation I have an observer that observes the event sales_order_invoice_pay. When this event triggers I'm attempting to store the invoice's ID in a custom model I've created.

Here's how I'm getting the invoice from the event: $invoice = $observer->getEvent()->getInvoice();

However, when I attempt this using: getId(), getData('entity_id'), getIncrementId(), or getOrigData('entity_id'), I receive a null value.

It's important for me to store this specific invoice id as I'm using it later to load that invoice and create a shipment for items invoiced.

Is there anyway for me to get the ID?


In your observer method you can do:

$invoice = $observer->getEvent()->getInvoice();

From this variable you get all the invoice data

  • Hi, Sorry for not being specific enough in my question, but I'm already getting that from the observer. The problem is that getting the id from that object is returning null – Ryan Cady Nov 4 '16 at 20:34
  • @RyanScottCady did you try using sales_order_invoice_save_after ? – Raphael at Digital Pianism Nov 4 '16 at 20:45
  • That event isn't available in Magento 1.9. Even if it was, that event would not be a good way as it updates every time the invoice saves, NOT when it's paid – Ryan Cady Nov 4 '16 at 20:51
  • 1
    @RyanScottCady it should work with this one and getId though. Are you sure your observer is getting called? – Raphael at Digital Pianism Nov 5 '16 at 7:31
  • 1
    I'll have to try it again. Once I find out I'll let ya know! – Ryan Cady Nov 6 '16 at 10:00

This is the same case as happened to me here

You'd observe sales_order_invoice_save_commit_after event, at this point invoice should be totally saved, so you could get entity_id value

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.