Prestashop:从 B.O 中删除姓氏字段规则验证

Prestashop : Remove Lastname Field Rules Validation From B.O

我正在尝试为客户的姓字段删除规则验证..

我已经通过编辑 Classes/Customer.php 文件在客户注册的首页成功完成了,如下所示:

'lastname' =>array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32),

至:

'lastname' =>array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 32),

我只是在验证中使用了 isAnything

但这在 后台 中不起作用,所以我无法从 BO 编辑客户。

找不到要更改的文件

我正在使用 Prestashop V1.7.6.8. 请需要帮助。谢谢

必须修改两个文件中的两个方法。

src/Core/ConstraintValidator/CustomerNameValidator.php,方法 isNameValid

private function isNameValid($name)
{
    return true; // Here true or your own validation.
    // Down the original code.
    $pattern = $this->characterCleaner->cleanNonUnicodeSupport(self::PATTERN_NAME);

    return (bool) preg_match($pattern, $name);
}

src/Core/Domain/Customer/ValueObject/LastName.php,方法 assertLastNameIsValid

private function assertLastNameIsValid($lastName)
{
    return true; // Here true or your own validation.
    // Down the original code.
    $matchesLastNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName));

    if (!$matchesLastNamePattern) {
        throw new CustomerConstraintException(sprintf('Customer last name %s is invalid', var_export($lastName, true)), CustomerConstraintException::INVALID_LAST_NAME);
    }
}