Accessing the Current Quote in Magento 2

Accessing the Current Quote in Magento 2

The quote holds the shopper’s cart before it becomes an order. In Magento 2 you reach it through the checkout session, injected into your class.

Example block

<?php
namespace Brush\CheckoutModification\Block;
use Magento\Checkout\Model\Session as CheckoutSession;
class CheckoutQuote
{
    private $checkoutSession;
    public function __construct(
        CheckoutSession $checkoutSession
    ) {
        $this->checkoutSession = $checkoutSession;
    }

    public function getQuote()
    {
        return $this->checkoutSession->getQuote();
    }
}

From the quote you can read items, totals and addresses. Avoid loading the quote in full page cached blocks, since cart data should come from customer data sections instead.

Want this done for you? Find out more about our Magento development service.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.