Magento – Magento Fetching Cart Items

cartmagento-1.9quote

I have items in cart. But it returns empty array when fetching them. I don't know what is the problem. I used following code for getting the number of items in cart and it gives 0.But in my site I have items in the cart.

$totalItems = Mage::helper('checkout/cart')->getItemsCount();
echo $totalItems;

$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllVisibleItems() as $item)
{
   $productid = $item->getProductId();
   $productsku = $item->getSku();
   $productname = $item->getName();
   $productqty = $item->getQty();
   echo $productid;
}

I hope someone will help on this issue.

Best Answer

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();

  foreach ($items as $item) {
       $itemId = $item->getItemId();
       $itemCount=$item->getName();
  }

Try this code

Related Topic