Hello,
I follow up from this old post:
www.hikashop.com/forum/install-update/88...t-part-of-email.html
Nicolas provided this solution
It uses the full email address for the username.
It can however be changed quite easily by changing the line:
$this->registerData->username = $this->registerData->email;
to:
$this->registerData->username = substr($this->registerData->email,0,strpos($this->registerData->email,'@'));
in the file administrator/components/com_hikashop/classes/user.php
but now my question is: what happens if there is already a user with that username?
eg. lots of users register with
This email address is being protected from spambots. You need JavaScript enabled to view it., thus you would end up with many "info" username wich would cause errors in the Joomla registration process
can the suggested code be easily changed to check for duplicates and in case add random numbers after the username?
Or it already does that?
On some forms by Chronoengine.com I have on the site, they suggested this code:
<?php
$user_name = explode('@', $form->data['email']);
$user_name = $user_name[0];
$db = \JFactory::getDBO();
$query = "
SELECT `username`
FROM `#__users`
WHERE `username` LIKE '{$user_name}%' ;
";
$db->setQuery($query);
$usernames = $db->loadColumn();
$temp = $user_name;
if ( count($usernames) > 0 ) {
while ( in_array( $temp, $usernames ) ) {
$temp = $user_name.'_'.rand(1111, 9999);
}
}
$form->data['user_name'] = $temp;
?>
Thank you!