How to Create Partial Invoice Programmatically Magento
In this post i am going to share code about how to create Partial Invoice for selected items from the order.
<?php
$orderID = "145000010"; //order increment id
$orderDetails = Mage::getModel('sales/order')->loadByIncrementId($orderID);
if($orderDetails->canInvoice() and $orderDetails->getIncrementId())
{
//$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$orderItems = $orderDetails->getAllItems();
$invoiceItems = array();
foreach ($orderItems as $_eachItem) {
$opid = $_eachItem->getId();
$opdtId = $_eachItem->getProductId();
$itemss = Mage::getModel('catalog/product')->load($opdtId);
$psku = $itemss->getSku(); // get product attribute which is used your condition
if($psku=='Test product1'){
$qty = $_eachItem->getQtyOrdered();
} else {
$qty = 0;
}
$itemsarray[$opid] = $qty;
}
if($orderDetails->canInvoice()) {
echo $invoiceId = Mage::getModel('sales/order_invoice_api')
->create($orderDetails->getIncrementId(), $itemsarray ,'Partially create Invoice programatically' ,0,0);
}
}
?>
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)

Hii
ReplyDeleteCan you provide me the path here to put this code actually iam very new to magento..Thanks
hi can u give suggestions for partial payment for a single product. Like for a single $100 product, like $70 and $30. 2 invoice for one product
ReplyDeleteIt is possible by Rest api for magento-2.1?When i have 2 item in order,1 is simple and other is bundle.If I will generate invoice for simple product,it give invoice id in response.In this Invoice,Simple product information as well as showing bundle product parent item information.Tell me what is issue?
ReplyDelete