public function createCustomer() { $customer = new self(); if ($customer->isGuest()) { $email = $customer->getEmail(); $user = UserInfo::getByEmail($email); if (!$user) { $password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 10); $mh = Core::make('helper/mail'); $mh->addParameter('siteName', Config::get('concrete.site')); $navhelper = Core::make('helper/navigation'); $target = Page::getByPath('/login'); if ($target) { $link = $navhelper->getLinkToCollection($target, true); if ($link) { $mh->addParameter('link', $link); } } else { $mh->addParameter('link', ''); } $valc = Core::make('helper/concrete/validation'); $min = Config::get('concrete.user.username.minimum'); $max = Config::get('concrete.user.username.maximum'); $newusername = preg_replace("/[^A-Za-z0-9_]/", '', strstr($email, '@', true)); while (!$valc->isUniqueUsername($newusername) || strlen($newusername) < $min) { if (strlen($newusername) >= $max) { $newusername = substr($newusername, 0, $max - 5); } $newusername .= rand(0, 9); } $user = UserInfo::add(array('uName' => $newusername, 'uEmail' => trim($email), 'uPassword' => $password)); if (Config::get('concrete.user.registration.email_registration')) { $mh->addParameter('username', trim($email)); } else { $mh->addParameter('username', $newusername); } $mh->addParameter('password', $password); $email = trim($email); $mh->load('new_user', 'vivid_store'); // login the newly created user User::loginByUserID($user->getUserID()); // new user password email $fromEmail = Config::get('vividstore.emailalerts'); if (!$fromEmail) { $fromEmail = "store@" . $_SERVER['SERVER_NAME']; } $fromName = Config::get('vividstore.emailalertsname'); if ($fromName) { $mh->from($fromEmail, $fromName); } else { $mh->from($fromEmail); } $mh->to($email); $mh->sendMail(); } else { // we're attempting to create a new user with an email that has already been used // earlier validation must have failed at this point, don't fetch the user $user = null; } } else { $user = $customer->getUserInfo(); } return $user; }