Search code examples
phpmagento

How do I get items in a Magento shopping cart using models?


Is there any code with which I could fetch items added to the shopping cart and their count from Magento using any models or helpers?


Solution

  • To get your cart object (in session) :

    $quote = Mage::getSingleton('checkout/session')->getQuote();
    

    Then, to get the list of items in the cart :

    $cartItems = $quote->getAllVisibleItems();
    

    Then, to get the count for each item :

    foreach ($cartItems as $item) {
        echo $item->getQty();
    }