Skip to main content
full code explanation
Source Link
DavidVR
  • 166
  • 7

change your event name to:declare observer

Demo/CustomerQuote/etc/frontend/events.xml

controller_action_postdispatch_customer_account_loginPost<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

    <event name="controller_action_postdispatch_customer_account_loginPost">
        <observer name="quote_cart" instance="Demo\CustomerQuote\Observer\QuoteObserver"/>
    </event>

</config>

in events.xml fileadd observer class

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructorDemo/CustomerQuote/Observer/QuoteObserver.php

<?php

namespace Demo\CustomerQuote\Observer;

use Magento\Checkout\Helper\Cart;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class QuoteObserver implements ObserverInterface
{

    protected $cartHelper;

    public function __construct(
     \Magento\Checkout\Helper\Cart   Cart $cartHelper
    )
    {
        $this->cartHelper = $cartHelper;
    }

    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
     
        $items = $this->cartHelper->getCart()->getItems();
        // Use this instead counting items
        $countedCartItems = $this->cartHelper->getSummaryCount();
    echo    \Zend_Debug::dump(count($items));
    echo $countedCartItems;   \Zend_Debug::dump($countedCartItems);
    exit;
    returndie;
 $this;   }
}

Hope it helps you

change your event name to:

controller_action_postdispatch_customer_account_loginPost

in events.xml file

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {
 
    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

declare observer

Demo/CustomerQuote/etc/frontend/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

    <event name="controller_action_postdispatch_customer_account_loginPost">
        <observer name="quote_cart" instance="Demo\CustomerQuote\Observer\QuoteObserver"/>
    </event>

</config>

add observer class

Demo/CustomerQuote/Observer/QuoteObserver.php

<?php

namespace Demo\CustomerQuote\Observer;

use Magento\Checkout\Helper\Cart;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class QuoteObserver implements ObserverInterface
{

    protected $cartHelper;

    public function __construct(
        Cart $cartHelper
    )
    {
        $this->cartHelper = $cartHelper;
    }

    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {    
        $items = $this->cartHelper->getCart()->getItems();
        // Use this instead counting items
        $countedCartItems = $this->cartHelper->getSummaryCount();
        \Zend_Debug::dump(count($items));
        \Zend_Debug::dump($countedCartItems);
        die;
    }
}
added 30 characters in body
Source Link
DavidVR
  • 166
  • 7

change your event name to: controller_action_postdispatch_customer_account_loginPost

controller_action_postdispatch_customer_account_loginPost

in events.xml file

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {

    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

change your event name to: controller_action_postdispatch_customer_account_loginPost

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {

    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

change your event name to:

controller_action_postdispatch_customer_account_loginPost

in events.xml file

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {

    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

added event name
Source Link
DavidVR
  • 166
  • 7

You havechange your event name to: controller_action_postdispatch_customer_account_loginPost

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {

    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

You have to add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {

    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

change your event name to: controller_action_postdispatch_customer_account_loginPost

And add this class \Magento\Checkout\Helper\Cart $cartHelper to your constructor

protected $cartHelper;

public function __construct(
     \Magento\Checkout\Helper\Cart $cartHelper
){
    $this->cartHelper = $cartHelper;
}

public function execute(Observer $observer) {

    $items = $this->cartHelper->getCart()->getItems();
    $countedCartItems = $this->cartHelper->getSummaryCount();
    echo count($items);
    echo $countedCartItems;
    exit;
    return $this;
}

Hope it helps you

updated variables names
Source Link
DavidVR
  • 166
  • 7
Loading
added 30 characters in body
Source Link
DavidVR
  • 166
  • 7
Loading
Source Link
DavidVR
  • 166
  • 7
Loading