Does anyone know how to get the total items in the cart?
I have tried everything and the result is always 0
/****************************/
After what seemed like many hours, I finally solved my issue.
For those wanting to use this, here is what I did:
In my model I created a function taking information from the $_SESSION['cart']
Code:
function allCartItems() {
$sessioncart = $_SESSION['cart'];/* store multi-dimensional array of shopping cart */
$items = array();
/* save each array key as a value, in our case we want just the total count of each item in the cart */
foreach($sessioncart as $cartitems) {
$items[] = $cartitems['count'];
}
$total = 0; /* reset variable total */
/* add together each item row's total item count */
foreach (array_filter($items) as $value) {
$total += $value;
}
/* display total items in the shopping cart */
echo $total;
}
Then in the View where you want the result displayed, call the function
Code:
$this->MOrders->allCartItems();