0

I am trying to get the total number of items in an order and display them in the shipment PDF.

I am using the below code but I doubles the amount of items. For example, if there is 1 item it gets displayed as 2

<?php $order = $this->getPdfHelper()->getOrder();
    if ($order->hasInvoices()) {
        $invIncrementIDs = array();
        $invItems = array();
        $total = -0;
        foreach ($order->getInvoiceCollection() as $inv) {
            $invIncrementIDs[] = $inv->getIncrementId();
            foreach ($inv->getAllItems() as $item) {
                $invItems[] = $item->getQty();
                $total = $total + ($item->getQty());
            }
        }
    }
?>


<br/>
<h3>
    <strong><?php echo $this->__("Number of items:") ?>&nbsp;<?php echo $total; ?></strong>
</h3>

I'm not sure why but I'm thinking its to do with:

 $total = $total + ($item->getQty());

Could anyone assist?

2 Answers 2

1
<?php $order = $this->getPdfHelper()->getOrder();
    $items = $order->getAllItems();
    foreach($items as $item){
        $qty = $item->getQtyShipped();
        $total = $total + $qty;
    }
?>

getQtyShipped(); Is the way to do it!

0

do you try this with configurable products? Then you count the configurable and the simple

4
  • I think you are right, its counting simple + configurable. I've tried getAllVisibleItems but its a non-object Commented Sep 30, 2014 at 9:10
  • getAllVisibleItems only exists on orders, not on invoices. I don'T see a way atm, to check whether an item is a child item. But what you can do is get the order and use getAllVisibleItems on the order. Commented Sep 30, 2014 at 9:20
  • Yes but getAllVisibleItems returns an empty Array Commented Sep 30, 2014 at 9:34
  • I think it is an answer. What he describes happens, when he counts simple an configurable items, case solved. Commented Sep 30, 2014 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.