Magento: get the last added product id and cart items

This code snippet demonstrates how to get the product id of the last product that was added to the shopping cart, as well as to get all the products currently in the shopping cart.

echo $productID."<br>";
echo $_product->getName()."<br>";

$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
	$productID = $item->getProductId();
	$productSku = $item->getSku();
	$productName = $item->getName();
	$productQty = $item->getQty();
	echo $productID."|".$productSku."|".$productName."|".$productQty."<br>";

Search within Codexpedia

Custom Search

Search the entire web

Custom Search