Magento 2 Get Shopping Cart Details- – In magento 2 we can use object manager to get the shopping cart details. It is a little bit different than the magento 1. Here in this tutorial we are going to explain how you can use object manager to get the Shopping cart details such as – Cart totals, total items, items details etc.
Magento 2 Get Shopping Cart Details | Items | Quantity Example
First you need to create the instance of object manager, then you need to create object for Magento\Checkout\Model\Cart. Here is an example –
Magento 2 Get Shopping Cart Details, Items Example:
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cartItems = $objectManager-?>create('Magento\Checkout\Model\Cart')->getQuote()->getAllVisibleItems(); if(count($cartItems)>0){ foreach($items as $item){ $product = $item->getProduct(); $smallImage = $product['small_image']; $qty = $item->getQty(); $itemName = $item->getName(); // .. Same You can get Other Details. } } ?> |
In the above example we have used object manager to get the cart items list. We have fetched the cart item name, Item Quantity and product image, on the same way you can get the other details related to the customer’s cart.