1

Here I want to generate a Custom Invoice with Custom data and format right after default invoice generation.

So I have added an observer sales_order_invoice_pay. here I want to get Order Id but I have no idea how can I get order id in this observer.

$order = $observer->getEvent()->getOrder();
$orderId = $order->getId(); //returning NULL

$order = $observer->getEvent()->getOrder();
$incrementId = $order->getIncrementId();//returning NULL

How can I get order id in this observer?

Thanks in Advance.

1 Answer 1

4

Try the following way:


/** @var \Magento\Sales\Model\Order\Invoice $invoice */
$invoice = $observer->getEvent()->getInvoice();
$order = $invoice->getOrder();
$incrementId = $order->getIncrementId();
4

Your Answer

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

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