While working many times we face the requirement to load the current quote of the customer to achieve needed functionality. We can get the current quote of the customer easily by loading the checkout session class \Magento\Checkout\Model\Session. Further we need to call getQuote() method of this class..

Example below will help you to achieve this:


namespace WebbyTroops\Checkout\Block;

class Quote extends \Magento\Framework\View\Element\Template
     * @var \Magento\Checkout\Model\Session
    protected $_checkoutSession;

     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Checkout\Model\Session $checkoutSession
     * @param array $data
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Checkout\Model\Session $checkoutSession,
        array $data = []
    ) {
        $this->_checkoutSession = $checkoutSession;
        parent::__construct($context, $data);

     * Get current quote of Customer
    public function getCurrentQuote()
        return $this->_checkoutSession->getQuote();

Get quote data or items/products added in it

Now you have loaded the quote of current customer. Further you can easily get its data like below:

$quote = $block->getCurrentQuote();
echo $quote->getId();

You can also get the items or products added in it using below code snippet:

foreach ($quote->getAllVisibleItems() as $item) {
    echo $item->getProductId();
    echo $item->getName();

Further if you need to load current logged in customer data using customer session then you can follow this article How to get current logged in customer data in Magento 2.