Jump to content

Manage lastname and firstname validation according to Customer class definition


periwinkle_fr

Recommended Posts

There is no way to override the validation regex mask provided in the src/Core/Domain/Customer/ValueObject/FistName.php and src/Core/Domain/Customer/ValueObject/lastName.php files.

Some people advised to alter those files :

but, it's not a good idea because changes could be overwrited in case of core update.

Instead of that, the validation process should use the Validate::isCustomerName() function to check is the field is valid or not.

I tryed to do it without altering the core by overriding the service "prestashop.core.form.identifiable_object.data_handler.customer_form_data_handler" like this 

https://devdocs.prestashop.com/1.7/modules/concepts/services/

Changing AddCustomerCommand class, EditCustomerCommand class, and finally FirstName and LastName classes 

It worked for the frontend but crashes the Backend with this error : 

Attempted to load class "CustomerFormDataHandler" from namespace "Pwk\PwkCustomer".
Did you forget a "use" statement for "PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataHandler\CustomerFormDataHandler"?

Is there a way to manage this ? Or an update of these classes should be possible 

Simply changing 

$matchesFirstNamePattern = preg_match('/^[¤|]*$/u', stripslashes($firstName));

by 

$matchesFirstNamePattern = \Validate::isCustomerName($firstName));

Best regards,

Edited by periwinkle_fr
I forgot the \ before \Validate in order to make it work. (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...