B-219 Sec-55 Noida, India
+918010221733

Magento: Register guest user to website if email provided

If your Magento website have feature where guest user can place an order without registering themself in your site, you can add them as a customer in your database. It helps in grouping the orders w.r.t email address in backend sales order. The only condition is that he should provide his email address while placing an order, which is quite obvious.
So here is a snipped of code you can insert where you are asking user to enter his email address. Just check if the user is already not registered in your site.

$e = $email; //provided by guest user

$store = Mage::app()->getStore();
$websiteId = Mage::app()->getWebsite()->getId();
$customerObj = Mage::getModel(‘customer/customer’);
$customerObj->website_id = $websiteId;
$customerObj->setStore($store);
$prefix = “mag”;
$pwd = uniqid($prefix);
$session = Mage::getSingleton(‘checkout/session’);
$fname = $session->getFirstname();
$lname = $session->getLastname();
$customerObj->setEmail($e);
$customerObj->setFirstname(‘Guest’);
$customerObj->setLastname(‘Guest’);
$customerObj->setPassword($pwd);
$customerObj->save();
$customerObj->sendNewAccountEmail(‘confirmed’); //auto confirmed

(Visited 65 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.