Oct 13, 2015
kalpesh

Magento get all items in cart

Magento get all the items currently in cart programatically using below code. You can place it anywhere you wish to get information, phtml or php file. Instead of Mage::getSingleton(‘checkout/session’)->getQuote() you can also use Mage::getSingleton(‘checkout/cart’)->getQuote() to get same results. If you want to see what all product information is retrieved you can use $product->getData() inside the foreach loop to display in array format.

$cart = Mage::getSingleton('checkout/session')->getQuote();
//$cart->getAllItems() to get ALL items, parent as well as child, configurable as well as it's simple associated item
foreach ($cart->getAllVisibleItems() as $item) {
        $product = $item->getProduct();
    $name = $product->getName();
    $sku = $product->getSku();
}

If you want all the items in collection format, you can call below code instead:

$itemsCollection = Mage::getSingleton('checkout/cart')->getQuote()->getItemsCollection();

1 Comment

  • Is it possible to to do cart and checkout functionality on same page and we continue till payment section by show hide form functionality by js.?

    Thanks

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions