普雷斯塔普 在注册表中添加额外的字段


Prestashop Add extra fields to registration form

我正在建立一个prestashop网站

企业买家无法注册帐户以查看产品,除非他们可以在注册中输入有效的EIN号码或有效的Duns & Brandstreet号码。

如何使之成为可能?

还有任何其他电子商务软件可以帮助我通过切换到它来解决这个问题吗?

您真正需要做的就是将字段添加到模板中,然后使用其他代码覆盖AuthController来处理新字段。

例如
<?php
class AuthController extends AuthControllerCore
{     
  public function preProcess()
  {
    // Additional pre-processing for the new form field
    if (Tools::isSubmit('submitAccount'))
    {
      if (!MyDBNumberValidationClass::verifyvalidnumber(Tools::getValue('db_number_field', 0)))
        $this->errors[] = Tools::displayError('The Dun and Bradstreet number you entered is invalid.'); 
    }
    parent::preProcess();
  }
}

我假设您正在对数字进行复杂的验证,这就是为什么对 MyDBNumberValidationClass::verifyvalidnumber() 的静态调用在上面的原因,但它同样可以通过任何简单的测试或AuthController中的附加函数覆盖上面的类定义验证。如果您添加两个字段(即 EIN 编号),则只需更改逻辑以仅在两个字段都无效时才处理生成错误;表单验证的成功基于$this->errors为空。

这只是常规解决方案的一部分,因为它只处理验证额外的字段。如果您需要对输入的数据实际执行某些操作,那么最好的方法是编写一个小处理程序模块,该模块将自身安装在hookCreateAccount

例如
public function hookCreateAccount($params)
{
  // Get the field data entered on the form
  $DB_number = $params['_POST']['db_number_field'];
  // Your custom processing...
}
请注意,无法

从此处退出帐户创建,因此如果出现问题,您将需要添加代码以通过电子邮件发送给商店所有者。