How to get InvoiceId from sales_order_invoice_pay in magento 2
-
14-04-2021 - |
Domanda
How to get invoiceId from sales_order_invoice_pay event.
$invoice = $observer->getEvent()->getInvoice();
$invoice->getIncrementId();
Can't get with this code But with sales_order_invoice_save_after event I can get the ID.
Can anyone help me out to get invoiceId from sales_order_invoice_pay
Soluzione
sales_order_invoice_pay
can provide order objects.From that order object, you can get invoices of an order, that can multiple invoices or single invoice.
$order = $observer->getEvent()->getOrder();
$invoiceList = $order->getInvoiceCollection();
if (count($invoiceList->getItems()) > 1) {
foreach ($invoiceList as $invoice){
$invoice->getIncrementId();
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange