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.
[code language=”php”]
$productID=Mage::getSingleton(‘checkout/session’)->getLastAddedProductId(true);
echo $productID."<br>";
$_product=Mage::getModel(‘catalog/product’)->load($productID);
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>";
}
[/code]
Search within Codexpedia
Search the entire web