Magento get all items in cart
Magento get all the items currently in cart programatically using below code. You can place it anywhere you wish to get information, phtml or php file. Instead of Mage::getSingleton(‘checkout/session’)->getQuote() you can also use Mage::getSingleton(‘checkout/cart’)->getQuote() to get same results. If you want to see what all product information is retrieved you can use $product->getData() inside the foreach loop to display in array format.
$cart = Mage::getSingleton(‘checkout/session’)->getQuote();
//$cart->getAllItems() to get ALL items, parent as well as child, configurable as well as it’s simple associated item
foreach ($cart->getAllVisibleItems() as $item) {
$product = $item->getProduct();
$name = $product->getName();
$sku = $product->getSku();
}
If you want all the items in collection format, you can call below code instead:
$itemsCollection = Mage::getSingleton(‘checkout/cart’)->getQuote()->getItemsCollection();