Magento – Get the last added product and cart items

This code will show you how to get the product id of the last product that was added to the shopping cart, and all the products currently in the shopping cart.

$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>";

}

Revisions

3 Responses to “Magento – Get the last added product and cart items”

  1. The Woo Refugee 07/07/2017 at 8:58 am #

    Does Magento cost much to run? I have been using WooCommerce for awhile, but they have really irritated me lately. I just got hit with a $10k bill for a few plugins I own (completely out of the blue). They have increased their prices by 50 on all annual renewals – without telling their customers! Seems pretty odd. But nevertheless, I am currently looking to jump ship and not sure which shopping cart platform to use with our store.

    • Sharing Solution 25/07/2017 at 4:40 pm #

      Hi,

      I think the cost will depend on the requirements of your business.

      Magento has a lot of built-in features, so you don't need to buy a lot of plugins.

      I see a lot of people have moved from WooCommerce to Magento with a half of cost and without renewal fee.

      If you need further suggestion, you can contact me via the email [email protected]
       

      Regards,

      Han.

  2. Rediffusion des données 20/04/2018 at 7:23 pm #

    Enjoyed every bit of your post.Much thanks again. Keep writing.

Leave a Reply to Rediffusion des données Click here to cancel reply.