1
votes

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.

I can't even seem to get the increment id from the invoice either, I've used, getIncrementId(), getData('increment_id').

I'm at a complete loss here.

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?

1

1 Answers

1
votes

Since the \Mage_Sales_Model_Order_Invoice::pay method which dispatches the sales_order_invoice_pay event is also called in \Mage_Sales_Model_Order_Invoice::capture the invoice may not be persisted at the time you are observing. Try using event sales_order_invoice_save_after which is dispatched after an invoice is saved. The increment should be saved and an id should be set.