Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get shopping cart details in Magento

Tags:

magento

I want to get the shopping cart details, by using Magento's getQuote function. How can I do this?

$cart = Mage::getModel('checkout/cart')->getQuote();

When I print the $cart Page stops execution and blank page is shown. But when I write

$cart = Mage::getModel('checkout/cart')->getQuote()->getData();

and print the $cart an array will show. But I want to track the complete cart data (product Id,Product price like all information).

Is there any other method by which I can find the shopping card data?

like image 727
mjdevloper Avatar asked Jan 07 '11 13:01

mjdevloper


People also ask

How do I find CART details in Magento 2?

Get the number of items in cart and total quantity in cart. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); $totalItems = $cart->getQuote()->getItemsCount(); $totalQuantity = $cart->getQuote()->getItemsQty();

How can I get current CART ID in Magento 2?

Retrieve Masked id (guest cart hash) from the cart id in Magento 2, You required the cart quote id. masked_id is stored in the quote_id_mask table, it's the randomly generated string for the guest customer quote in Magento 2. Call method, $quoteId = 1; echo $maskedId = $this->getQuoteMaskId($quoteId);

What is Magento shopping cart?

A shopping cart enables the buyers to track their progress on an online shop or view the existing items from the same page. With Magento, you can easily configure various kinds of shopping carts that display different information to the customers and maintain a better shopping experience.

How do I get all quotes in Magento 2?

If you want to get all the items, like for a configurable product, the main item with child item data, will be displayed if you use $quote->getAllItems() function. getAllItems() returns all the quote item data.


1 Answers

The object returned by getQuote is a Mage_Sales_Model_Quote. It has a method getAllItems which in turn returns a collection of Mage_Sales_Model_Quote_Item objects.

All this means you can inspect products like this:

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    $productId = $item->getProduct()->getId();
    $productPrice = $item->getProduct()->getPrice();
}

PS. The reason you get a blank page is because dumping a whole object likely fell into recursion and the page timed out, or PHP ran out of memory. Using getData or debug is safer but, as you saw, doesn't return the protected/private variables.

like image 121
clockworkgeek Avatar answered Oct 01 '22 01:10

clockworkgeek