Magento2 Magento 2如何以编程方式登录特定存储中的用户

Magento2 Magento 2如何以编程方式登录特定存储中的用户,magento2,magento2.2,Magento2,Magento2.2,如何在Magento 2中以编程方式登录特定商店中的客户? 我已尝试重写的执行方法 Magento\Customer\Controller\Account\LoginPost 做了这样的事情: $this->storeManager->setCurrentStore("store_code"); $store = $this->storeRepository->getActiveStoreByCode("store_code"); $this->httpContex


如何在Magento 2中以编程方式登录特定商店中的客户?
我已尝试重写的执行方法

Magento\Customer\Controller\Account\LoginPost

做了这样的事情:

$this->storeManager->setCurrentStore("store_code");
$store = $this->storeRepository->getActiveStoreByCode("store_code");
$this->httpContext->setValue("store", "store_code", "default");
$this->storeCookieManager->setStoreCookie($store);

$customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
$this->session->setCustomerDataAsLoggedIn($customer);

但是它不起作用。

正如你所想,它更难。 您不能设置cookie存储或其他类似的设置。
作为解决方法,您可以通过ajax查询将凭证发布到特定的存储,如果响应成功,您可以将客户重定向到该存储

谢谢你的指导。我已经通过ajax将post请求连同客户电子邮件发送给我的控制器,在那里我检查哪个客户组的客户是谁,并根据此返回所需的商店。然后发送带有凭据的帖子登录到该商店。