Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get items in shopping cart using models? (Magento)

Tags:

magento

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?

like image 408
balanv Avatar asked Apr 01 '11 10:04

balanv


People also ask

How do I view items in my Magento 2 cart?

You can use the hasProductId function to check if a product is available in the cart or not. You should use the session factory to get the checkout session.


2 Answers

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();
}
like image 85
Hervé Guétin Avatar answered Oct 10 '22 13:10

Hervé Guétin


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

$items = $quote->getAllVisibleItems();

foreach($items as $cartItem) {
    echo $cartItem->getQty();
}

To get the total count in the cart you can use:

 Mage::getSingleton('checkout/cart')->getSummaryQty();
like image 20
Drew Hunter Avatar answered Oct 10 '22 14:10

Drew Hunter