Magento creates a partial invoice programmatically

In a specific order, I want to create an invoice for some selected items from this order.

I have successfully created an invoice for the entire order programmatically, but I want to create a partial invoice for this order.

+7
order magento invoice
source share
2 answers

Atlas, I get it. Had to dig magento to get this.

$orderid // order id $order = Mage::getModel('sales/order')->load($orderid); or for order increment id $orderincrmentid // order increment id $order = Mage::getModel('sales/order')->loadByIncrementId($orderincrmentid); if($order->canInvoice()) { $invoiceId = Mage::getModel('sales/order_invoice_api') ->create($order->getIncrementId(), $itemsarray ,'your_comment' ,1,1); } echo $invoiceId; // Gives increment Invoice id 

@parameters for the create function above:

1st parameter: order increment identifier

Second parameter: array

 // array format . [Main point] foreach($order->getAllItems() as $item) { $item_id = $item->getItemId(); //order_item_id $qty = $item->getQtyOrdered(); //qty ordered for that item } array('56'=>'3','57'=>'1','58'=>'0'); array([order_item_id] => [qty]); // general array format 

So, here you add the identifier of the order item as a key and its value as its value.
If you do not want to create an account identifier for a specific element, simply pass the value of its quantity as 0 // zero .

Third parameter: comment

4th parameter: send mail ----> 1 do not send mail ----> 0

5th parameter: include a comment in the mail ----> 1 do not include the comment in the mail ----> 0

It returns the invoice identifier of the account.

Hope this helps someone.

+12
source share

Try this one ...

 <?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); } } ?> 

For more info

+1
source share

All Articles