Reputation: 80
I just want to know the syntax of adding the quantity using foreach
.
Any help is greatly appreciable.
Here is the code what I do so far:
$qproducts = '0';
foreach ($this->cart->getProducts() as $product) {
$qproducts .= $product['quantity'];
}
$this->data['pquantity'] = $qproducts;
Upvotes: 3
Views: 9442
Reputation: 9858
You mean like this?
$qproducts = 0;
foreach ($this->cart->getProducts() as $product) {
$qproducts += $product['quantity'];
}
$this->data['pquantity'] = $qproducts;
Upvotes: 5
Reputation: 838276
Use +
(addition) instead of .
(concatenation).
$qproducts = 0;
foreach ($this->cart->getProducts() as $product) {
$qproducts += $product['quantity'];
}
Upvotes: 4