如何获得发票项目的数量

时间:2014-03-20 05:58:28

标签: php magento

我正在创建部分发票,但我无法让qty invoiced将其发送到付款网关。

我在capture()的模型中编写的代码是:

        if ($order->hasInvoices()) {
            foreach ($order->getInvoiceCollection() as $invoice) {
                foreach ($invoice->getAllItems() as $item) {
                    Mage::log($item->getQtyInvoiced()); // getting qty = 0
                }
            }
        }

另外,下次我想创建发票,然后$order->hasInvoices()返回false

上面的代码是对的吗?有关调试发票项目的任何说明将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试这是否适合您。

// 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>