Milind Daraniya

How to Get Current Quote ID from Checkout Session in Magento 2

Published August 5th, 2023 6 min read

In Magento 2, the quote ID is essential for retrieving and manipulating the current quote (or cart) information during the checkout process. In this tutorial, we'll guide you through the process of getting the current quote ID from the checkout session in Magento 2.

To get the current quote ID from the checkout session, you can utilize the Magento\Checkout\Model\Session class. This class provides methods to access various data related to the checkout session, including the quote ID. Here's an example of how you can retrieve the current quote ID:

<?php

use Magento\Framework\App\Bootstrap;
use Magento\Checkout\Model\Session as CheckoutSession;

require __DIR__ . '/app/bootstrap.php';

// Bootstrap Magento
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

// Retrieve the checkout session
$checkoutSession = $objectManager->get(CheckoutSession::class);

// Get the current quote ID
$quoteId = $checkoutSession->getQuoteId();

echo "Current Quote ID: " . $quoteId;

?>

The code above retrieves the current checkout session using the CheckoutSession class and then calls the getQuoteId() method to get the quote ID. You can use this quote ID for further operations or to retrieve additional information about the current quote.