Reputation: 10888
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?
Upvotes: 12
Views: 49860
Reputation: 176
You can also do
$cartItems = Mage::getModel("checkout/cart")->getItems();
foreach($cartItems as $item) {
// Do what you want
}
Upvotes: 2
Reputation: 10888
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
$itemId = $item->getItemId();
$itemCount=$item->getQty();
}
This code will also help...
Upvotes: 3
Reputation: 10114
$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();
Upvotes: 7
Reputation: 4392
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();
}
Upvotes: 45