Get all items information in cart
$ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
$ cart = $ objectManager ->get ('\Magento\Checkout\Model\Cart ' );
// retrieve quote items collection
$ itemsCollection = $ cart ->getQuote ()->getItemsCollection ();
// get array of all items what can be display directly
$ itemsVisible = $ cart ->getQuote ()->getAllVisibleItems ();
// retrieve quote items array
$ items = $ cart ->getQuote ()->getAllItems ();
foreach ($ items as $ item ) {
echo 'ID: ' .$ item ->getProductId ().'<br /> ' ;
echo 'Name: ' .$ item ->getName ().'<br /> ' ;
echo 'Sku: ' .$ item ->getSku ().'<br /> ' ;
echo 'Quantity: ' .$ item ->getQty ().'<br /> ' ;
echo 'Price: ' .$ item ->getPrice ().'<br /> ' ;
echo "<br /> " ;
}
Get total items 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 ();
Get subtotal and grand total price of cart
$ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
$ cart = $ objectManager ->get ('\Magento\Checkout\Model\Cart ' );
$ subTotal = $ cart ->getQuote ()->getSubtotal ();
$ grandTotal = $ cart ->getQuote ()->getGrandTotal ();
Get billing and shipping addresses
$ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
$ cart = $ objectManager ->get ('\Magento\Checkout\Model\Cart ' );
$ billingAddress = $ cart ->getQuote ()->getBillingAddress ();
echo '<pre> ' ; print_r ($ billingAddress ->getData ()); echo '</pre> ' ;
$ shippingAddress = $ cart ->getQuote ()->getShippingAddress ();
echo '<pre> ' ; print_r ($ shippingAddress ->getData ()); echo '</pre> ' ;