How to Get Current Quote Id by Checkout Session Magento 2?

To Retrieve Current Quote Id from the cart checkout page, You need to use a checkout session to fetch all the information related to quote data.

Use Magento\Checkout\Model\Session to inject the object using the class __construct() method. While you working with the checkout page and need to fetch quote data by current quote id, in this case this article is useful for you.

Checkout session contains the quote data and using session fetch getQuote(), based on the quote, you can get any quote related data.

<?php
namespace Jesadiya\QuoteId\Model;

use Magento\Checkout\Model\Session as CheckoutSession;

class CheckoutQuote
{
    /**
     * @var CheckoutSession
     */
    private $checkoutSession;

    public function __construct(
        CheckoutSession $checkoutSession
    ) {
        $this->checkoutSession = $checkoutSession;
    }

    /**
     * Checkout quote id
     *
     * @return int
     */
    public function getQouteId()
    {
        return (int)$this->checkoutSession->getQuote()->getId();
    }
}

Use Function with the method name,

echo $quoteId = $this->getQouteId();

You can also Optionally declare Session class as a proxy in the di.xml file to prevent resource-hungry specific class and call Session class as needed in the class.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Jesadiya\QuoteId\Model\CheckoutQuote">
        <arguments>
            <argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
        </arguments>
    </type>
</config>

Above Given XML File, Pass type name attribute value as Original Class Name with argument name is the checkoutSession and add suffix as the Proxy for the given class.