I am using magento 2 + react (frontend). I have setup grapql to interconnect with frontend-backend functionality
I have Customer Logout event in module which is not triggering, i do not see any error in logs.
Any thoughts, if it need any correction ? Thanks
app/code/Vendor/Module/etc/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="customer_logout">
<observer instance="Vendor\Module\Observer\CustomerLogout" name="customer_logout_observer"/>
</event>
</config>
app/code/Vendor/Module/Observer/CustomerLogout.php
<?php
namespace Vendor\Module\Observer;
use Vendor\Module\Helper\Tracking;
use Magento\Framework\Event\ObserverInterface;
use Psr\Log\LoggerInterface;
class CustomerLogout implements ObserverInterface
{
/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* @var Tracking
*/
protected $helper;
public function __construct(LoggerInterface $logger, Tracking $helper)
{
$this->logger = $logger;
$this->helper = $helper;
}
/**
* @param Observer $observer
* Call helper & pass customer object
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/customerlogout.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('CustomerLogout event');
$customer = $observer->getEvent()->getCustomer();
$this->helper->trackLogOut($customer);
} catch (\Exception $e) {
$this->logger->info($e->getMessage());
}
}
}