To authorize by phone number you need to add the appropriate field. How this can be done is described in the previous article.

By default, Presta Shop users are authorized by E-mail. Often it is not convenient, and then there is a need for identification by phone number. To do this type of work we need the function “Overrides“, which can change the standard behavior of Presta Shop.

In the folder at /override/classes/form/ create
file a CustomerLoginFormatter.php, responsible for the output of the authorization form, and give it a class.

class CustomerLoginFormatter extends CustomerLoginFormatterCore

Next, adjust the code,

’email’ => (new FormField)
‘Phone’, [], ‘Shop.Forms.Labels’

This will allow the buyer to enter a phone number and not to validate this field as E-mail.

The last action is to override the class Сustomer.php, namely the getByEmail method responsible for user identification on the site.

if (!Validate::isPhoneNumber($email) || ($plaintextPassword && !Validate::isPasswd($plaintextPassword))) {

And compare the username in the SQL query.

$sql->where(‘ = ”.pSQL($email).”’);

Congratulations! Now the user can log in to the personal account of the online store by phone number.

Download source materials