0

I want to make a change of store view through code. I have created the next plugin for when the user logs in the system makes a change of store view, but the change is not maintained, I want to switch to store view DE but when I open a product or a category the change is lost. This is my code:

<?php
namespace MyPlugin\CustomerLogin\Plugin;

class LoginPostPlugin
{

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $_storeManagerInterface;

    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
    ) {
        $this->_storeManagerInterface = $storeManagerInterface;
    }


    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        //-- check group is retail customer or not
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $objectManager->create('Magento\Customer\Model\Session');
        if ($customerSession->isLoggedIn()){
            $groupId = $customerSession->getCustomerGroupId();
            if ($groupId == 2){
                $this->_storeManagerInterface->setCurrentStore(1);
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

Can someone help me solve my problem? I need to simulate the change of store view but I need the change to be maintained

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.