How to get Cart info in magento2

How to get Cart info in Magento2:
Using below script we get the current cart details.

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

 $cartObj = $objectManager->get('\Magento\Checkout\Model\Cart');

 //Your Quote collection
 $cartItemsCollection = $cartObj->getQuote()->getItemsCollection(); 

 //Get cart items
 $cartItemsVisible = $cartObj->getQuote()->getAllVisibleItems(); 

 $itemsArray = $cartObj->getQuote()->getAllItems();

foreach($itemsArray as $item) {
 echo $item->getProductId(); //Product ID
 echo $item->getName(); //Product Name
 echo $item->getSku(); //Product SKU
 echo $item->getQty(); //Product Qty
 echo $item->getPrice(); //Product Price
 }

CORNER OF BLOG:

“Don’t Waste Water to Taste it Later.”

Leave a Reply