I need to create all suborder invoice of an order in magento. i used this code but my amount is coming 0 .

$order = Mage::getModel('sales/order')->loadByIncrementId(100000067);
$items = $order->getItemsCollection();

$items = array(); //this will be used for processing the invoice

   foreach ($order->getAllItems() as $item) {
    $items[$item->getId()] = $item->getQtyOrdered();

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

// The rest is only required when handling a partial invoice as in this example
$amount = $invoice->getGrandTotal();
echo $amount;

$history = $invoice->getOrder()->addStatusHistoryComment(
    'Partial amount of $' . $amount . ' captured automatically.', false




How to create all suborder invoice of an order.... like if my order id 110101 and if contain 5 sku (101,102,103,104,105) for this i want to create suborder invoice of order in magento......

but when i apply the given answer my amount is coming 0. enter image description here


1 Answer 1


If you want to create sku respective sub invoice then try this.

   foreach ($order->getAllItems() as $item) {
        // create invoice for sku MatchSKU 
       // example MatchSKU =101 if  
         $items[$item->getId()] = $item->getQtyOrdered();

Instead of :

 foreach ($order->getAllItems() as $item) {
    $items[$item->getId()] = $item->getQtyOrdered();

If you want to each item respective invoice then try this:

foreach ($order->getAllItems() as $item) :
    $itemsQty = array();
    $itemsQty[$item->getId()] = $item->getQtyOrdered();

          if (!$order->canInvoice()) {
           echo  Mage::helper('sales')->__('Cannot do invoice for order.');

        $invoice = $order->prepareInvoice($itemsQty);


       // if want to add comment when invoice creating 
            $invoice->addComment($comment='Test comment', $email=true);

        // send  new  invoice email


        try {
            $transactionSave = Mage::getModel('core/resource_transaction')

            $invoice->sendEmail($email, ($includeComment ? $comment : ''));
        } catch (Mage_Core_Exception $e) {
           // there  have an error


  • MatchSKU is just for one sku...but i want all sub skus of orders...
    – Deepak Rai
    Sep 18, 2015 at 18:51
  • this error is coming Cannot do invoice for order.Cannot do invoice for order.Cannot do invoice for order.Cannot do invoice for order.
    – Deepak Rai
    Sep 18, 2015 at 19:44
  • ...why amount is coming 0 in invoice I added screen shoot..pls have a look
    – Deepak Rai
    Sep 18, 2015 at 20:19
  • i will check...
    – Amit Bera
    Sep 19, 2015 at 5:52
  • if i add a link on orders ...in sub sku..then i get order is there..but how i will get skus there....here i got Order id ..<td class="a-right last" ><a href="<?php echo Mage::helper('adminhtml')->getUrl("magazineadmin/adminhtml_magazine/create", array('order_id'=>$this->getOrder()->getRealOrderId())); ?>">Create Invoice</a></tr> </tr>...but also i need skus...of orders..hope u understand...
    – Deepak Rai
    Sep 19, 2015 at 5:57

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.