Reputation: 79
I have a order with 3 items: 1º product x 1 qnt 2º product x 2 qnt 3º product x 1 qnt
if i use:
$_order = $this->getOrder();
foreach ($_order->getAllItems() as $items){
$qnttotal = $items->getQtyOrdered();
result in 1.
if i use:
$_order = $this->getOrder();
foreach ($_order->getAllItems() as $items){
$qty = $items->getQty();
}
result in: "NULL".
How do I return me 3 (total of products)? thanks
Upvotes: 0
Views: 493
Reputation: 286
You can get total qty from order object directly no need of iteration.
Please check below code:
$_order = $this->getOrder();
echo 'Total qty is '.$_order->getTotalQtyOrdered();
And if you want total item ordered tha please check below code:
$_order = $this->getOrder();
echo 'Total Item is '.$_order->getTotalItemCount();
I hope it will help you.
Upvotes: 1
Reputation: 1548
Try this for total line items;
$count = 0;
$_order = $this->getOrder();
foreach ($_order->getAllItems() as $items){
$count++
}
echo 'Total lines is '.$count;
Or this for total qty;
$totalqty = 0;
$_order = $this->getOrder();
foreach ($_order->getAllItems() as $items){
$totalqty = $totalqty + $items->getQtyOrdered();
}
echo 'Total qty is '.$totalqty;
Upvotes: 0