Nicolased Posted September 23, 2019 Share Posted September 23, 2019 (edited) Hi evryone, On prestashop 1.7.6, french, i have to made some overide ( or in core) For link to business soft i need to allow Number in FIRST NAME and LAST NAME. I find some trick who explain this: Change Validate.php or change customer .php I try to remove some characters validate .php in line 182 public static function isName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^(?:[^0-9!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); To : public static function isName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^*$/u' ); But i still the same I can't creat new user with only number I try this action: , as not well Blank screen ... I have to made a restore a backup... Does anyone now solution on prestashop 1.7.6.1? thx for answer 🙂 Edited September 24, 2019 by Nicolased (see edit history) Link to comment Share on other sites More sharing options...
Nicolased Posted September 23, 2019 Author Share Posted September 23, 2019 Nobody? Work good on 1.7.4 I found difference between 1.7.4 and 1.7.6 . In CUSTOMER.php, the field call "isCustomerName" not "isName" but problem stay the same. Nothing append -when i change "isCustomerName" ( in validate.php, remove 0-9) When i change the field 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 255), by isGenericName for test . 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), It's very strange, because try on old 1.7.4 and it work like charm. Very strange. Link to comment Share on other sites More sharing options...
Nicolased Posted September 24, 2019 Author Share Posted September 24, 2019 Ok I find the solution: Change validate.php in /classes/ public static function isCustomerName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^0-9(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); return preg_match($validityPattern, $name); } To public static function isCustomerName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); return preg_match($validityPattern, $name); } After: You must have change 2 files: in: src/Core/Domain/Customer/ValueObject/ There is 2 files : FirstName.php LastName.php change : private function assertLastNameIsValid($lastName) { $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 ); } By: private function assertLastNameIsValid($lastName) { $matchesLastNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName)); if (!$matchesLastNamePattern) { throw new CustomerConstraintException( sprintf('Customer last name %s is invalid', var_export($lastName, true)), CustomerConstraintException::INVALID_LAST_NAME ); } ( In fact remove characters you want, for me only 1-9) by the way , do the same with firstname: { $matchesFirstNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName)); if (!$matchesFirstNamePattern) { throw new CustomerConstraintException( sprintf('Customer first name %s is invalid', var_export($firstName, true)), CustomerConstraintException::INVALID_FIRST_NAME ); } } by { $matchesFirstNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName)); if (!$matchesFirstNamePattern) { throw new CustomerConstraintException( sprintf('Customer first name %s is invalid', var_export($firstName, true)), CustomerConstraintException::INVALID_FIRST_NAME ); } } 3 1 Link to comment Share on other sites More sharing options...
SomeUnknownGuy Posted July 23, 2020 Share Posted July 23, 2020 (edited) Hello! I created an account just to confirm that the above solution works. I'm deploying version 1.7.6.7 Thank you! Edit: it works until the customer attempts to edit their own profile, in case they wanted to add/modify their shipping address. In such case, the last name containing numbers becomes an issue. I am attempting to investigate and solve this... Edited July 23, 2020 by SomeUnknownGuy added screenshot (see edit history) Link to comment Share on other sites More sharing options...
SomeUnknownGuy Posted July 23, 2020 Share Posted July 23, 2020 Okay, found solution. In addition to the changes in Validate.php in /classes/, made by Nicolased, here: On 9/24/2019 at 7:07 PM, Nicolased said: Change validate.php in /classes/ public static function isCustomerName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^0-9(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); return preg_match($validityPattern, $name); } To public static function isCustomerName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); return preg_match($validityPattern, $name); } One more additional code modification is needed, in order to avoid name validation if the customer edits their own profile, to the same Validate.php file, in /classes/, as follows: From: public static function isName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u' ); return preg_match($validityPattern, $name); } To: public static function isName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u' ); return preg_match($validityPattern, $name); } 1 Link to comment Share on other sites More sharing options...
apositivo Posted September 14, 2020 Share Posted September 14, 2020 On 9/24/2019 at 1:07 PM, Nicolased said: Ok I find the solution: Change validate.php in /classes/ public static function isCustomerName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^0-9(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); return preg_match($validityPattern, $name); } To public static function isCustomerName($name) { $validityPattern = Tools::cleanNonUnicodeSupport( '/^(?:[^!<>,;?=+()\/\\@#"°*`{}_^$%:¤\[\]|\.。]|[\.。](?:\s|$))*$/u' ); return preg_match($validityPattern, $name); } After: You must have change 2 files: in: src/Core/Domain/Customer/ValueObject/ There is 2 files : FirstName.php LastName.php change : private function assertLastNameIsValid($lastName) { $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 ); } By: private function assertLastNameIsValid($lastName) { $matchesLastNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($lastName)); if (!$matchesLastNamePattern) { throw new CustomerConstraintException( sprintf('Customer last name %s is invalid', var_export($lastName, true)), CustomerConstraintException::INVALID_LAST_NAME ); } ( In fact remove characters you want, for me only 1-9) by the way , do the same with firstname: { $matchesFirstNamePattern = preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName)); if (!$matchesFirstNamePattern) { throw new CustomerConstraintException( sprintf('Customer first name %s is invalid', var_export($firstName, true)), CustomerConstraintException::INVALID_FIRST_NAME ); } } by { $matchesFirstNamePattern = preg_match('/^[^!<>,;?=+()@#"°{}_$%:¤|]*$/u', stripslashes($firstName)); if (!$matchesFirstNamePattern) { throw new CustomerConstraintException( sprintf('Customer first name %s is invalid', var_export($firstName, true)), CustomerConstraintException::INVALID_FIRST_NAME ); } } thank you ! this work for me in prestashop 1.7.6.7 ! for admin dashboard and front (user dashboard - update lastname and firstname) Link to comment Share on other sites More sharing options...
MJ_C Posted October 27, 2020 Share Posted October 27, 2020 Many thanks, much appreciated. I had the validate but not seen the firstname and lastname php files Link to comment Share on other sites More sharing options...
jvlucas Posted November 12, 2020 Share Posted November 12, 2020 thank you, this work for me but, how to allow numbers in address´s firstname and lastname too? Link to comment Share on other sites More sharing options...
antoniocici Posted January 13, 2021 Share Posted January 13, 2021 First of all, thank you for your useful suggestion. I've to add one more modification required to the code in order to allow to edit a customer from the BackOffice. To complete the solution proposed by @Nicolased we have to make the following change inside the file: /src/Core/ConstraintValidator/CustomerNameValidator.php at the line 40, change the constant as follow const PATTERN_NAME = '/^(?!\s*$)(?:[^!<>,;?=+()\/\\\\@#"°*`{}_^$%:¤\[\]|。]|[。\.](?:\s|$))*$/u'; Without this change, I can't edit and save a customer with numbers in firstname or lastname from the backoffice. 1 Link to comment Share on other sites More sharing options...
apositivo Posted January 13, 2021 Share Posted January 13, 2021 3 hours ago, antoniocici said: First of all, thank you for your useful suggestion. I've to add one more modification required to the code in order to allow to edit a customer from the BackOffice. To complete the solution proposed by @Nicolased we have to make the following change inside the file: /src/Core/ConstraintValidator/CustomerNameValidator.php at the line 40, change the constant as follow const PATTERN_NAME = '/^(?!\s*$)(?:[^!<>,;?=+()\/\\\\@#"°*`{}_^$%:¤\[\]|。]|[。\.](?:\s|$))*$/u'; Without this change, I can't edit and save a customer with numbers in firstname or lastname from the backoffice. thank you for this update @antoniocici, is very important ! Link to comment Share on other sites More sharing options...
webjosegm Posted June 3, 2021 Share Posted June 3, 2021 (edited) Hi! this solution works for prestashop 1.7.7.4 Great work!! Thanks! Edited June 3, 2021 by webjosegm (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now