1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
$email = 'customer@email.com'; $firstname = 'Magen'; //Customer's firstname $lastname = 'Tools'; //Customer's lastname $pwd_length = 7; //auto-generated password length $customer = Mage::getModel('customer/customer'); $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); $customer->loadByEmail($email); if(!$customer->getId()) { //We're good to go with customer registration process $customer->setEmail($email); $customer->setFirstname($firstname); $customer->setLastname($lastname); $customer->setPassword($customer->generatePassword($pwd_length)); } //if process fails, we don't want to break the page try{ $customer->save(); $customer->setConfirmation(null); //confirmation needed to register? $customer->save(); //yes, this is also needed $customer->sendNewAccountEmail(); //send confirmation email to customer? } catch(Exception $e){ Mage::log($e->__toString()); } |
Awsome code
Saved me from lot of effort doing such code.