Here, We are discussing on how we can get all shopping cart items and totals in magento. It will be helpful in the cases if we need to show the informations regarding the cart and items somwhere in the website

So 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

<?php // $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$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 "";
}
?>

Get total items and total quantity in cart

<?php $totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
?>

Get subtotal and grand total price of cart

<?php $subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
?>

Hope this helps to get all shopping cart items and totals in magento

Leave a Reply

Your email address will not be published.