Search code examples
prestashopprestashop-1.6prestashop-1.7prestashop-modulesprestashop-helper-classes

Prestashop : Remove Lastname Field Rules Validation From B.O


I am trying to remove rules validation for customer's Lastname field..

I have succeed to do it in the front page for customer registration by editing Classes/Customer.php file like this:

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

to :

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

I have simply used isAnything in validation.

But that's not working in the Backoffice, so i can't edit customers from BO.

Can't find what file to change exactly.

I am using Prestashop V1.7.6.8. Need help please. Thanks


Solution

  • You must modify two methods in two files.

    src/Core/ConstraintValidator/CustomerNameValidator.php, method 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, method 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);
        }
    }