cancel
Showing results for 
Search instead for 
Did you mean: 

Simulate click on the drop-down to change the store view by code

Simulate click on the drop-down to change the store view by code

I need to be able to simulate the click of the drop-down of the view change but with code. I do not have space to put the drop-down and I would like to simulate the click by code but I have no idea how to do it. Could someone help me do this?

2 REPLIES 2

Re: Simulate click on the drop-down to change the store view by code

Hi @ManuelSissl 

Try once using jQuery trigger with change event.

For more info:
https://api.jquery.com/change/

I hope it will help you!

Re: Simulate click on the drop-down to change the store view by code

Hi,

 

I created this plugin but it does not work, could you help me make the store view change work?

 

<?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(2);
                $result->setPath('?___store=DE&___from_store=DE');
            }
        }
        return $result;
    }
}

My problem is that the change of view is applied correctly when the client of group 2 does log in, but if the client opens a product or opens a category, it loses the store view that it selects by code and returns to the previous store view. Could you help me please?