2

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?

0

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();
        }
    }

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.