Magento GuideCart → Get All Products

How to get all products from a Magento 2 cart

Need to retrieve every product from a Magento 2 shopping cart? Whether you’re customizing the checkout flow or syncing data to an external system, Magento’s quote object makes it possible. Let’s walk through how to get all cart items—and the key data that comes with them.

Host Magento at full throttle.

Get secure, reliable Magento hosting so you can scale faster.

Why would you need to get all cart items?

Accessing all products in a Magento 2 cart is a common requirement for both frontend customization and backend automation. Here are some scenarios where this is essential:

If your module or extension needs to understand what’s in the cart, accessing the quote object is the right place to start.

Access the quote object in Magento 2

The quote object stores all information about the current shopping cart. You can access it through the checkout session.

Inject the session dependency

Use dependency injection in your constructor:

Load the quote

Then retrieve the quote like this:

This $quote object now gives you full access to all cart data.

Get all cart items from the quote

Magento provides two ways to get cart items:

Example:

You can use this data in templates, APIs, or logic modules.

Extract subtotal, grand total, and addresses

The quote object also gives you access to financial and customer address information.

Subtotals and totals

Use this for building invoices, payment summaries, or validating discounts.

Billing and shipping addresses

This is helpful for custom shipping logic or syncing with external systems.

Get quote items by ID or SKU

If you only need certain items from the cart, you can filter based on product ID or SKU:

Each $item also includes methods like getId(), getPrice(), and getProductType().

Display cart items in a template file

You can show quote items in a .phtml file by exposing the quote from a block class.

Block class method:

Template file example:

Use this to customize the shopping cart or checkout summary page.

Export cart products for integration or reporting

To pass cart data to an external service or report, loop through the items and store the data in an array or JSON string.

Example export array:

You can now send $json to an API, save it to a file, or use it in your custom module.

FAQs

Use the quote object via $this->checkoutSession->getQuote() and loop through $quote->getAllItems() or $quote->getAllVisibleItems() to retrieve all products.

Inject Magento\Checkout\Model\Session, call getQuote(), and then use methods like getAllItems(), getSubtotal(), and getBillingAddress() to retrieve full cart data.

To export all catalog products, use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory. To export products in the current cart, use $quote->getAllItems() and export the data to JSON or CSV.

After loading the quote with getQuote(), use getAllItems() or getAllVisibleItems() to access individual quote items, each of which includes product details like SKU, quantity, and name.

Next steps for getting all products from a Magento 2 cart

Accessing quote data is a key part of building Magento 2 modules, from simple cart displays to full checkout customization and external system integration. It’s one of the most flexible and powerful tools in the Magento toolbox.

To continue, try loading and filtering cart data from an observer or API endpoint to fit your unique use case.

Ready to upgrade your Magento experience? Professional hosting improves speeds, security, and reliability for a website and a brand that people find engaging and trustworthy.

Liquid Web offers the raw infrastructure power you need with mission-critical features that keep your store running smoothly. Most importantly, our in-house Magento experts are standing by to help with both hosting and Magento application roadblocks.

Click through below to explore all of our Magento hosting options, or chat with an expert right now to get answers and advice.

Ready to get started?

Get the fastest, most secure Magento hosting on the market

Additional resources

What is Magento Ecommerce? →

A complete beginner’s guide to the Magento Ecommerce platform

Magento shopping cart: How to setup, optimize, and manage →

Let’s walk through everything you need to know about configuring, optimizing, and maintaining your Magento cart the right way.

Best Magento ERP extensions →

Our top 10 compared so you can decide which is best for your business