0

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; $invoice->register()->pay(); $invoice->getOrder()->setIsInProcess(true); $history = $invoice->getOrder()->addStatusHistoryComment( 'Partial amount of $' . $amount . ' captured automatically.', false ); $history->setIsCustomerNotified(true); $order->save(); Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()) ->save(); 

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

3
  • are want to create each sku respective sub invoice Commented Sep 18, 2015 at 18:42
  • @AmitBera yes...I want create invoice by skus of order.....but its come 0 amount always Commented Sep 18, 2015 at 18:45
  • @AmitBera I want to use this logic ..stackoverflow.com/questions/14059179/… Commented Sep 18, 2015 at 18:59

1 Answer 1

0

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

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

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); $invoice->register(); // if want to add comment when invoice creating $invoice->addComment($comment='Test comment', $email=true); // send new invoice email $invoice->setEmailSent(true); $invoice->getOrder()->setIsInProcess(true); try { $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()) ->save(); $invoice->sendEmail($email, ($includeComment ? $comment : '')); } catch (Mage_Core_Exception $e) { // there have an error } $invoice->getIncrementId(); endforeach; 
5
  • MatchSKU is just for one sku...but i want all sub skus of orders... Commented 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. Commented Sep 18, 2015 at 19:44
  • ...why amount is coming 0 in invoice I added screen shoot..pls have a look Commented Sep 18, 2015 at 20:19
  • i will check... Commented 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... Commented Sep 19, 2015 at 5:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.