客户是否可以使用客户编号而不是电子邮件地址登录


12

我想创建一个使用分配的客户编号而不是其电子邮件地址的登录页面。在单独的eComms平台上,我的业务设置方式是,他们使用客户编号访问其帐户,因为他们是一个帐户的多个客户经理。我为他们创建帐户,然后分配一个客户编号,然后将其用于登录并输入密码。

任何帮助将不胜感激。


我担心这对于本网站来说太过难了。是的,这是可能的,但是要进行此工作,将需要进行大量的代码重写和模板更改等工作。
David Manners 2015年

谢谢大卫,我虽然可能是这种情况,但是我值得一试。
Alex WG 2015年

Answers:


8

只需很少的自定义代码即可实现基本逻辑:

写了一个观察者controller_predispatch_customer_account_loginPost,检查是否张贴的电子邮件地址(username)并没有看起来像一个电子邮件地址。在这种情况下,请按客户编号查找客户,然后用找到的客户的实际电子邮件地址替换POST数据中的用户名字段。

观察者代码示例:

$request = $observer->getControllerAction()->getRequest();
$username = $request->getPost('username');
if (false === strpos($username, '@')) {
    $customer = Mage::getModel('customer/customer')
        ->getCollection()
        ->addAttributeToFilter('customer_number', $username)
        ->getFirstItem();
    if ($customer && $customer->getEmail()) {
        $request->setPost('username', $customer->getEmail());
    }
}

然后在中controller_postdispatch_customer_account_loginPost,将会话中的电子邮件地址替换回客户编号(如果已设置)。否则,登录失败的错误消息将包含电子邮件地址而不是数字。

观察者代码示例:

$emailAddress = Mage::getSingleton('customer/session')->getUsername();
if ($emailAddress) {
      $customerNumber = Mage::getModel('customer/customer')->loadByEmail($emailAddress)
          ->getCustomerNumber();
}
Mage::getSingleton('customer/session')->setUsername($customerNumber);

要考虑的其他事项:

  • 将相同的逻辑应用于“忘记密码”表格
  • 确定是否要使用内置的increment_id客户编号,您可以在系统配置中的“ 客户配置”>“创建新帐户选项”>“生成友好的客户ID”下启用该编号

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.