SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH
get the current quote in Magento 2
Magepow.com

How to get the current quote in Magento 2

Hi everyone, Today I will show you how to get the current quote in Magento 2.

Step 1. Create block file

Magepow/GetQuote/Block/GetQuote.php with content bellow

namespace Magepow/GetQuote/Block;

use Magento\Backend\App\Action;


class GetQuote extends Action
{

    protected $checkoutSession;

    public function __construct(
              \Magento\Checkout\Model\Session $checkoutSession    
           )
    {
        $this->checkoutSession = $checkoutSession;
    }

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


    }
}

Now we call our function and get a quote data.

$allItems = $this->getQuotes()->getAllVisibleItems();
foreach ($allItems as $item) {
    echo $item->getProductId();
}

Done, I hope this article will helpful for you.