Home » Magento, Magento 25 September 2016

Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

This article shows how to get shopping cart items/products, subtotal and grand total of cart, and shipping and billing address entered while doing checkout in Magento 2.

I will be using both Dependency Injection (DI) and Object Manager in the below example code.

Using Object Manager

– Get products id, name, price, quantity, etc. present in your cart.
– Get number of items in cart and total quantity in cart.
– Get base total price and grand total price of items in cart.
– Get billing and shipping addresses entered during checkout.

Get all items information in cart

Get total items and total quantity in cart

Get subtotal and grand total price of cart

Get billing and shipping addresses

Using Dependency Injection (DI)

In the above code in Object Manager, I have used object of class \Magento\Checkout\Model\Cart to fetch shopping cart items and totals. But, we can also use the object of class \Magento\Checkout\Model\Session.

Here is your block class code:

Your .phtml template code:

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Keyur Shah

    Thanks for the article. Can you show how to do this without using the object manager S Magento is now recommending

  • san

    how to do this in observer.
    i want this data in checkout after adding shipping address…

  • Marcos Tadeu

    Class Cart is Deprecated !!! ???

  • Sarvesh Kumar Tiwari

    i have added your block code in my block and phtml code in phtml but its not working for me.