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?

1 Answer 1


James As you want you works in on invoice creation time you can use getOrigData('entity_id')

On creation on invoice it always give the null value and you can use sales_order_invoice_save_after events

so you try use

$invoiceId = $observer->getEvent()->getInvoice()->getOrigData('entity_id');
if(is_null($invoiceId )){
// do your logic

an for getting item qty try this

   foreach ($invoice->getAllItems() as $item){
                if ($item->getOrderItem()->getParentItem()) {
                /* Draw item */

        $name = $item->getName();
        $type = $item->getSku();
        $id = $item->getProductId();
        $qty = $item->getQty();

  • @AmithBera thanks. I used the sales_order_invoice_pay event itself and used your function to get the item qunatity
    – James
    Oct 8, 2014 at 12:12

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.