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?
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();
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);
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With