From a specific order I want to create an invoice for some selected items from that order.
I have successfully created an invoice for the whole order programmatically, b
Try this one...
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);
}
}
?>
For more info