3

Magento 2: After Customer Login Get Cart Information?

On observer I got 2 active quote id's. I can get by latest from quote table.

Is there any way to get current quote id?

1

1 Answer 1

-2

Please check with below code, i hope its work for you.

<?php

    namespace Adamsmage\Login\Observer;
    use \Magento\Framework\Event\Observer;
    use \Magento\Framework\Event\ObserverInterface;

    use \Magento\Checkout\Model\Session as CheckoutSession;

    class AddtoCart implements ObserverInterface {

        /** @var CheckoutSession */
        protected $checkoutSession;

        /**
         * @param CheckoutSession $checkoutSession
         */
        public function __construct(CheckoutSession $checkoutSession) {
            $this->checkoutSession = $checkoutSession;
        }

        public function execute(Observer $observer) {
            /** @var \Magento\Catalog\Model\Product\Interceptor $product */
            $product = $observer->getProduct();

            /** @var \Magento\Quote\Model\Quote  */
            $quote = $this->checkoutSession->getQuote();
        }
    }
1
  • The answer below is correct but copied from magento.stackexchange.com/questions/106717/… would recommend going to original source – Dava Gordon
    – Black
    Dec 10, 2020 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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