You can fetch the quote object by quote id in Magento 2.
Load quote by id using CartRepositoryInterface of Quote Module. If you are working for cart-related functionality and if you need to load quote data, in this case, you have helped this article.
Useful Interface,
Magento\Quote\Api\CartRepositoryInterface
<?php namespace Jesadiya\Quote\Model; use Psr\Log\LoggerInterface; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Api\Data\CartInterface; class QuoteById { /** * @var CartRepositoryInterface */ public $quoteRepository; /** * @var LoggerInterface */ public $logger; public function __construct( CartRepositoryInterface $quoteRepository, LoggerInterface $logger ) { $this->quoteRepository = $quoteRepository; $this->logger = $logger; } /** * Get Quote By Id * * @param int $quoteId * * @return CartInterface|null */ public function getQuoteById(int $quoteId): ?CartInterface { $quote = null; try { $quote = $this->quoteRepository->get($quoteId); } catch (NoSuchEntityException $exception) { $this->logger->error( 'Quote does not exist'., [$exception->getMessage()] ); } return $quote; } }
Call from template file,
$quoteId = 1;
$quote = $this->getQuoteById($quoteId);
You can retrieve quote related data using above way.