Home » Magento25 April 2011

Magento: Get all shopping cart items and totals

Here, I will show you how you can get information about all items in your Magento Shopping Cart. You will see how you can :-

– Get products id, name, price, quantity, etc. present in your cart.
– Get number of items in cart and total quantity in cart.
– Get base total price and grand total price of items in cart.

Get all items information in cart

Get total items and total quantity in cart

Get subtotal and grand total price of cart

Hope this helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Anonymous

    it’s easy to lose items this should help find them.steroids

  • Pingback: Magento ordered products when checkout | deepinphp.com()

  • Its a nice blog , thanks for sharing the information.

  • Giovanni

    Thank you Mukesh.
    But how can you get product options?

  • Anonymous

    Could you explain how to get a  configurable product sku,name to show up in the cart and order instead of the simple product sku in magento 1.5.0.

    The below code returns the Sku for the simple product, how can i retrieve the Sku for its parent product
    product_id=”getSku() ?>”

  • Anonymous

    Could
    you explain how to get a  configurable product sku,name to show up in
    the cart and order instead of the simple product sku in magento 1.5.0.

    The below code returns the Sku for the simple product, how can i retrieve the Sku for its parent product
    product_id=getSku() ?>

     

  • Michael Isakov

    This is amazing, thanks

  • Jeff Kayne

    thanks man, few more questions,

    how to get the products link and the thumbnail images of those are in the shopping cart 

  • Anonymous

    Hi – I can display products following your examples but can not display the cart – must be a problem with getting at the session variables.  Could you show the full code?  My code is as follows but displays nothing

    ‘frontend’));
    $items = Mage::getSingleton(‘checkout/session’)->getQuote()->getAllItems();
     
    foreach($items as $item) {
        echo ‘ID: ‘.$item->getProductId().”;
        echo ‘Name: ‘.$item->getName().”;
        echo ‘Sku: ‘.$item->getSku().”;
        echo ‘Quantity: ‘.$item->getQty().”;
        echo ‘Price: ‘.$item->getPrice().”;
        echo “”;
    }

  • Anonymous

    Ignore that last comment – i’ve spent a few hours agonising over this only to suddenly realise my cart was empty!!

  • naresh

    hello mukesh ,

    your code is work fine but i can get price .
    what an issue ?

  • naresh

    ignore first comment .
      i can’t get price.
    what an issue ?

  • gopal

    how to set grand total and subtotal of cart?????

  • Ralph

    Hi. Is there a way to also get the custom options selected by the user ? Like, if a user has chosen medium as a custom option for size, could that be retrieved as well?(was able to do this inside default.phtml on the cart page but need to do this on view.phtml)

  • Ralph

    Hi. Is there a way to also get the custom options selected by the user ? Like, if a user has chosen medium as a custom option for size, could that be retrieved as well?(was able to do this inside default.phtml on the cart page but need to do this on view.phtml)

  • I just got a blank screen using Mage::getModel(‘checkout/cart’)->getQuote()->getAllItems() inside a block method…
    Does it works for Magento 1.6 ?

    Thanks for helping.

  • I just got a blank screen using Mage::getModel(‘checkout/cart’)->getQuote()->getAllItems() inside a block method…
    Does it works for Magento 1.6 ?

    Thanks for helping.

    (sorry for replying bellow – its nos associated with the DianaBol thread)

  • Igor Bobriakov

    Your post helps a lot, thanks!

  • Venz Bg

    How you can get the Regular Price of a cart item?

  • pratik

    good one .,.

  • Dave

    Using getAllItems() can cause problems with configurable products… they would show up twice… in this case I would use:

    Mage::getSingleton(‘checkout/session’)->getQuote()->getAllVisibleItems();

  • Cristian

     I’d like to know too…. Nobody knows?

  • Gourav

    how can i display proceed to checkout or google checkout or any button display on add to cart success message please help me i already waste too much time.
    Please help me i m waiting………………….

  • To beginners this would be a great help, seeing this code many might be thinking that Magento development is easy to deal which according to me is not a case. This is just an simple case but for complex part, Magento looks much harder to deal with.

  • jeremy

    how do you format the totals to a currency format?

  • manthan

    we can also get current quote items collection using getItems() method

    $cart = Mage::getModel(‘checkout/cart’)->getItems();
    print_r($cart->getData());

  • manthan

    use this code

    $cart = Mage::getModel(‘checkout/cart’)->getItems();
    print_r($cart->getData());

  • brij

    how to load cart by customer id for example $cart=Mage::getModel(‘checkout/cart’)->load($customerId);
    but this is not working how this work

  • Ron Duque

    grandTotal is not updating when the user back to shipping method and select new shipping ,method.. The shipment fee should also update when display in phtml files.

  • PHP Guru

    I’m trying to make a simple ajax endpoint in an analytics extension that returns the products in the cart. No matter what code I try, the result is empty. No errors, there’s just never anything in the cart array – getItems( ) returns [ ]. I suspect it has to do with the session not getting started correctly. Any ideas?