Is there any code with which i could fetch items added to the shopping cart and their count from magento using any models or helpers?
You can use the hasProductId function to check if a product is available in the cart or not. You should use the session factory to get the checkout session.
To get your cart object (in session) :
$quote = Mage::getSingleton('checkout/session')->getQuote();
Then, to get the list of items in the cart :
$cartItems = $quote->getAllVisibleItems();
Then, to get the count for each item :
foreach ($cartItems as $item) {
echo $item->getQty();
}
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
foreach($items as $cartItem) {
echo $cartItem->getQty();
}
To get the total count in the cart you can use:
Mage::getSingleton('checkout/cart')->getSummaryQty();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With