命令上的Magento 2实例AccountManagement

时间:2017-05-03 15:20:26

标签: magento2

如何在自定义模块中的Command中实例Magento\Customer\Model\AccountManagement

我试图创建一个重置所有客户密码的命令

1 个答案:

答案 0 :(得分:0)

您可以在AccountManagementInterface使用DI,就像从Magento's code获取的代码段一样:

class Command
{
    public function __construct(
        AccountManagementInterface $customerAccountManagement
    ) {
        $this->customerAccountManagement = $customerAccountManagement;
    }

    public function whatever() {
        $this->customerAccountManagement->initiatePasswordReset(
            $email,
            AccountManagement::EMAIL_RESET
        );
   }
}