I need to invoice my order automatically whenever shipment is done, but if say I ship only one item of multiple items order then invoice should also be created for only that item not for all. I am using following code after setting a observer whenever shipped but it is invoicing all items even if I ship just one:

public function invoicedStatusChange($observer)
       $shipment = $observer->getEvent()->getShipment();
       $order = $shipment->getOrder();
           $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
           $transactionSave = Mage::getModel('core/resource_transaction')

Thanks in advance


Take a look at https://magento.stackexchange.com/a/11075/519

You need to include the qty of each item shipped

  foreach(get item collection just ship){
    $qtys[$item->getId()] = $item->getQtyShipped();

  Mage::getModel('sales/service_order', $order)->prepareInvoice($qtys);


Take a look at database table sales_flat_order_item


Note: you may need to get the qty from the $shipment, since the above fields store the total

| improve this answer | |
  • I am new to magento, so can you please elaborate, as now how can i fetch this value for $qty_to_invoice – Inder Jun 30 '15 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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