/** * @param $email * @param $context * @return Pap_Affiliates_User */ private function createUserFromEmail($email, $context) { $context->debug('Loading affiliate by email'); $emailValidator = new Gpf_Rpc_Form_Validator_EmailValidator(); if (!$emailValidator->validate($email)) { if (!$emailValidator->validate(urldecode($email))) { $context->debug(' AutoRegisteringAffiliates - Creating affiliate stopped, not valid email address: ' . $email); return null; } $email = urldecode($email); } try { return Pap_Affiliates_User::loadFromUsername($email); } catch (Gpf_Exception $e) { if (!Pap_Common_User::isUsernameUnique($email)) { $context->debug(' AutoRegisteringAffiliates - Creating affiliate stopped, email address is used for another user: '******''); $user->setLastName(substr($email, 0, strpos($email, '@'))); //$user->setSendNotification(false); $user->save(); $signupForm->setDefaultEmailNotificationsSettings($user); $signupContext = Pap_Contexts_Signup::getContextInstance(); $signupContext->setUserObject($user); $merchantNotificationEmails = new Pap_Signup_SendNotificationEmails(); $merchantNotificationEmails->process($signupContext); $context->debug(' AutoRegisteringAffiliates - New Affiliate created successfully, email: ' . $email); Gpf_Db_Table_UserAttributes::setSetting(self::AUTO_REGISTERED_AFFILIATE, Gpf::YES, $user->getAccountUserId()); } return Pap_Affiliates_User::loadFromUsername($email); }