I have already implemented This solution , but it is not working for me
I am trying to redirect customer after login to different page rather than my account
What i tried
\app\code\Mycompany\Customerhomepage\etc\frontend\events.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/framework/Event/etc/events.xsd">
<event name="customer_login">
<observer name="mycompany_customerhomepage_customer_login" instance="Mycompany\Customerhomepage\Observer\Customerlogin"/>
</event>
</config>
\app\code\Mycompany\Customerhomepage\Observer\Customerlogin.php
<?php
namespace Mycompany\Customerhomepage\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\App\ResponseFactory;
/**
* Class customerlogin
* @package Mycompany\Customerhomepage\Observer
*/
class customerlogin implements ObserverInterface{
protected $_responseFactory;
protected $_url;
/**
* @param UrlInterface $url
* @param ResponseFactory $responseFactory
*/
public function __construct(
\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\UrlInterface $url
) {
$this->_responseFactory = $responseFactory;
$this->_url = $url;
}
/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
$customerBeforeAuthUrl = $this->_url->getUrl('customerhomepage/index/landing');
$this->_responseFactory->create()->setRedirect($customerBeforeAuthUrl)->sendResponse();
die();
}
}
It also exhibiting in variable behavior , sometime it redirects sometime it does not
controller_action_predispatch
event: magento.stackexchange.com/questions/131706/…