I need to observe the invoice creation event and get only the invoiced item quantities since I use partial invoicing sometimes.
I tried the events sales_order_invoice_save_after
and sales_order_invoice_pay
and found that sales_order_invoice_save_after
is fired every time a change is made to invoice. So i used sales_order_invoice_pay
and got the items into a log using this code
$invoice = $observer->getEvent()->getInvoice();
foreach ($invoice->getAllItems() as $item) {
$name = $item->getName();
$type = $item->getSku();
$id = $item->getProductId();
$qty = $item->getQty();
Mage::log($name.' '.$type.' '.$id.' '.$qty.' '.$parentId , null, 'test.log', true);
}
Most of my products are configurable products. In the log file I get two lines for the same order, configurable product details and simple product details. Also the $qty
value for the configurable product shows the invoiced quantity(in case of partial invoice) and the simple product $qty
shows the ordered quantity.
How do I get only the simple product details with the invoiced qunatity?
Best Answer
James As you want you works in on
invoice creation time you can
usegetOrigData('entity_id')
On creation on
invoice it always give the null value
and youcan use sales_order_invoice_save_after
eventsso you try use
an for getting item qty try this