How to get shopping cart items and totals in magento

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

How to get shopping cart items and totals in magento

How to get shopping cart items and totals in magento

Here, We will explain How to get shopping cart items and totals in magento?

The code for getting all items in shopping cart:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// retrieve quote items collection
$itemsCollection = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection();
 
// get array of all items what can be display directly
$itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
 
// retrieve quote items array
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
 
foreach($items as $item) {
	echo 'ID: '.$item->getProductId().'<br />';
	echo 'Name: '.$item->getName().'<br />';
	echo 'Sku: '.$item->getSku().'<br />';
	echo 'Quantity: '.$item->getQty().'<br />';
	echo 'Price: '.$item->getPrice().'<br />';
	echo "<br />";			
}

The code for getting total items and quantity of shopping cart:

1
2
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();

The code for getting subtotal and grand total price of shopping cart:

1
2
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();

Add comment


 

Pin It on Pinterest

Share This