Sunday, 20 November 2011

Auto Login customer to Magento

In various scenario of the Magento developer need to Auto login a customer. Here is the magic code to do that:


// => if you know the customer id
$customer = Mage::getModel('customer/customer')->load($id);
// => if you know the customer email address
$customer = Mage::getModel('customer/customer')->loadByEmail('some@email.com');

if($customer->getId())
{
Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
}

12 comments :

  1. You're my savior man!!! Thanks a thousend times. I've been looking for that for some time now. It really made my day and developing a lot easier.

    ReplyDelete
  2. You are most welcome James. Sole purpose of this blog to share the ideas.

    ReplyDelete
  3. Hi there, just became alert to your blog through Google, and found that it's truly informative. I am going to watch out for brussels. I will appreciate if you continue this in future. Many people will be benefited from your writing. Cheers!

    ReplyDelete
  4. I would like to express my admiration for your kindness giving support to persons that need assistance with this important topic. Your personal commitment to getting the message all over appears to be exceptionally practical and have consistently encouraged professionals just like me to achieve their goals. The useful instruction entails so much to me and somewhat more to my colleagues. Thanks a ton; from each one of us.

    ReplyDelete
  5. I simply want to say I'm very new to weblog and definitely savored your blog. Almost certainly I’m likely to bookmark your website . You definitely come with good article content. Thanks for sharing your webpage.

    ReplyDelete
  6. Excellent blog right here! Additionally your web site quite a bit up fast! What host are you using? Can I get your associate hyperlink on your host? I wish my web site loaded up as fast as yours lol

    ReplyDelete
  7. This article has inspired me to continue writing on my own blog

    ReplyDelete
  8. Loving the information on this website , you have done outstanding job on the blog posts.

    ReplyDelete
  9. this post shows the information which is close to standard. convincing way of expression due to that reason your post become so informative.

    ReplyDelete
  10. Can any body tell me where to write (page/phtml/controller file) this code in .

    ReplyDelete
  11. i have a core php site i login in this i want to use this login id and password in magento session.

    ReplyDelete