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 snippet 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 |
UPDATE: It depends where you want to keep this functionality on your site. I have put it in saveShippingMethodAction() function of Mage/Checkout/controllers/OnepageController.php file after extending. Don’t forget, this code should only be run if customer is guest.
10 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Which file to update for this functionality?
Great thanks!
Which file to update for this functionality?
where to put this code ?
in which file ?
Please check my update in the post to know where to place the code.
still i am getting issue in registering the guest user ,
can you please explain in details.or if you have alternative to register the guest customer after they place order
u can use this code in observer
which observer file paste this code please explain clearly
Do you have this code for magento 2?
Excellent article. I absolutely love this site.
Thanks!