Blog navigation keyboard_arrow_down

Blog Rss rss_feed

User authorization via phone

User authorization via phone

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)
->setName('phone')
->setType('text')
->setRequired(true)
->setLabel($this->translator->trans(
'Phone', [], 'Shop.Forms.Labels'
))
->addConstraint('isPhoneNumber'),

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

image-3_3.png

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))) {
die(Tools::displayError());
}

And compare the username in the SQL query.

$sql->where('c.phone = ''.pSQL($email).''');

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

Was this blog post helpful to you?

    
No comments at this moment
close

Checkout

close

Favourites