I can't get the current quote in the Product view page. I have 3 items in my cart.

I have used both files.

use Magento\Checkout\Model\Session;
use Magento\Checkout\Model\Cart;

$quote = $this->_checkoutSession->getQuote();
echo $quote->getId();

But, I can't get it. After that adding new product in view page. I can got it.

How to do that.


  • Where you use this code ? In observer or? Please explain more. – Rohan Hapani Aug 5 at 11:55
  • I used this code in the custom model file in view page. – Mano M Aug 5 at 11:56
  • I want to get a quote on page load – Mano M Aug 5 at 12:00
  • Let me know if you still can't able to get quote. – Rohan Hapani Aug 5 at 12:23

I think u have to add getAllVisibleItems() for get quote item

    $om = \Magento\Framework\App\ObjectManager::getInstance();
    $cartData = $om->create('Magento\Checkout\Model\Cart')->getQuote()->getAllVisibleItems();
    echo $cartData->getId();
  • Its also not working – Mano M Aug 5 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.