How to create partial invoice?

后端 未结 2 709
南笙
南笙 2021-02-04 16:47

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

2条回答
  •  猫巷女王i
    2021-02-04 17:41

    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

提交回复
热议问题