How to get all the Products of Cart in Magento

magento

In Magento or any E-Commerce Cart is the important feature. Cart always helps to show items added for buying with its quantity , Item Name and its price.
We can see total amount we need to pay .
Some time shipping is also shown in the cart else in other cases shipping is been seen in the checkout process.
So as a Magento Developer we can get Magento Cart items any where and we can show it with all the details.
For example lets create cms page or block and set it with any phtml file.
Then Paste below code to get all the cart items with Product Name, Price , Quantity etc.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>How to get all the Products of Cart in Magento</title>
</head>
<body>
<!-- How to get all the Products of Cart in Magento-->
<?php
 //Get All the Products of Cart
 $cart = Mage::getModel('checkout/cart')->getQuote();
 $items = $cart->getAllVisibleItems();
 foreach ($items as $itemId => $item) 
 {
	echo 'Pid='.$productId  = $item->getProductId();
	echo '<br>';
	echo 'itemid='.$itemId  = $item->getItemId();
	echo '<br>';
	echo 'qty='.$productQty = $item->getQty();
	echo 'price='.$productQty = $item->getPrice();
	//Load Product Collection to get All the Details of Products
	$product = Mage::getModel('catalog/product')->load($productId);
 }
?>
Posted in Uncategorized