Reputation: 5959
I'm creating a partial invoice and I'm unable to get the qty invoiced
to send it to the payment gateway.
The code I'd written in my model for capture()
is:
if ($order->hasInvoices()) {
foreach ($order->getInvoiceCollection() as $invoice) {
foreach ($invoice->getAllItems() as $item) {
Mage::log($item->getQtyInvoiced()); // getting qty = 0
}
}
}
also, for the next time I do want to create the invoice then $order->hasInvoices()
returning false
.
Is the above code is right? Any note on debug the invoice items will be appreciated.
Upvotes: 0
Views: 3803
Reputation: 4590
Try if this works for you.
// Load the order by order increment id(100000003 is my order increment id)
$order = Mage::getModel('sales/order')->loadByIncrementId(100000003);
if ($order->hasInvoices()) { // check if the order has invoice
$invIncrementIDs = array(); //array to store invoice numbers
$invItems = array(); // array to store the invoiced qunatity of each item
$total = 0; // variable to calculate the total number of items invoiced for the order
foreach ($order->getInvoiceCollection() as $inv) { // loop through each invoice
$invIncrementIDs[] = $inv->getIncrementId(); // store each invoice number in the array
foreach ($inv->getAllItems() as $item) { // get all the invoiced items of the particular invoice
$invItems[] = $item->getQty(); // get the invoiced qunatity for each item
$total = $total + ($item->getQty()); // sum up the total number of invoice items for the whole site
}
}
}
?>
// I used the above code in a test php page, so i used this to print the result in the page. You may not require this. Instead you can try logging these details.
<pre>
<?php echo $total; ?><br/>
<?php print_r($invItems); ?>
<?php print_r($invIncrementIDs); ?>
</pre>
Upvotes: 1