I'm a Magento 2 newbie. In my site we have 2 store- default and wholesale.
Account Login to default store will be like this - http://example.com/customer/account/login/ and for wholsesale store http://example.com/wholesale/customer/account/login
When I try to login to two store using different account from same browser it will work, but when I try to logout from one store it logging me out from another store also. How I can prevent this. I need to keep logging me in another(wholesale) store even if I logged out from default store.
I need this to work on same browser.
I created a module and tried to override logout action.
This is my code:
<?php
namespace Customvendor\Custommodule\Controller\Customer;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use \Magento\Framework\Controller\ResultFactory;
class Logout extends \Magento\Framework\App\Action\Action
//class Logout extends \Magento\Customer\Controller\Account\Logout
{
/**
* @var Session
*/
protected $customerSession;
public function __construct(
Context $context,
Session $customerSession
) {
//$this->session = $customerSession;
parent::__construct($context);
$this->redirect = $context->getRedirect();
$this->customerSession = $customerSession;
}
public function execute() {
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$customerId = $this->customerSession->getId();
if($customerId) {
//echo $customerId;exit;
$this->customerSession->logout()
->setBeforeAuthUrl($this->redirect->getRefererUrl())
->setLastCustomerId($customerId);
$this->messageManager->addSuccess(__('Logout successfully'));
return $resultRedirect->setPath('customer/account/login/');
} else {
$this->messageManager->addSuccess(__('Customer is not logged in'));
return $resultRedirect->setPath('customer/account/login/');
}
}
}
This is my store view
Please help me to fix this issue. Thanks in advance