首页 文章

Magento 2如何以编程方式登录特定商店中的用户

提问于
浏览
0

如何在Magento 2中以编程方式在特定商店中登录客户?
我试图覆盖 execute 方法

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);

但它没有用 .

1 回答

  • 0

    你想的更难 . 你不能设置cookie商店或其他东西 . 作为解决方法,您可以通过ajax查询将凭据发布到特定商店,如果响应已成功 - 您可以将客户重定向到该商店 .

相关问题