magento2 - Magento 2如何以编程方式登录特定商店的用户
问题描述
如何在 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 查询将凭据发布到特定商店,如果响应成功 - 您可以将客户重定向到该商店。
推荐阅读
- eclipse-plugin - 如何在自定义的 Eclipse 中安装自己编写的插件?
- flutter - 数值未显示在颤振图表上
- php - 使用 NetBeans 和 Apache 进行 PHP Xdebug
- visual-studio - 下载 vsix 依赖项以进行离线安装
- matlab - 寻找一种从绘图中提取数据的工具(这里是协方差矩阵或马尔可夫链中的 2D 轮廓)并重现原始图
- c# - Efcore:无法跟踪实体类型“x”的实例。多对多
- linux - 在虚拟框中使用 xdotool 模拟右 CTRL 键
- javascript - 正则表达式替换为变量
- c++ - 如何使用“getline()”比较每一行的第三个标记?
- wagtail - 从数据库中检索不同 wagtail 应用程序的数据