Magento2 – How to load Quote by Quote id
()

Use \Magento\Quote\Api\CartRepositoryInterface Repository as a dependency to create its instance and load the quote using id.

 
private $repository;

public function __construct( 
    ...... 
    \Magento\Quote\Api\CartRepositoryInterface $cartRepository 
    ...... 
) {
     $this->repository = $cartRepository;
} 

.... 

$quote = $this->repository->get($quoteId);
.... 

Alternatively you can also get quote using \Magento\Quote\Model\QuoteFactory model. But this has been deprecated, since entities are not responsible to load their own data.

To load quote data using \Magento\Quote\Model\QuoteFactory model, Use the code below:

......
private $quoteFactory;

public function __construct(
  .....
  \Magento\Quote\Model\QuoteFactory $quoteFactory
  ......
){
   $this->quoteFactory = $quoteFactory;
}

To use it you can write:

 
$q = $this->quoteFactory->create()->load($quoteId);


\Magento\Quote\Model\QuoteFactory model loads only current store specific quote. While using \Magento\Quote\Api\CartRepositoryInterface you can load any store cart data.

If you want to load specific store quote data using \Magento\Quote\Model\QuoteFactory model, you will have to specify the store id before calling load method.

$q = $this->quoteFactory->create()->setStoreId($storeId)
              ->load($quoteId);

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

2 Comments

  • Hi , Thats great brother 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *