Jul 26, 2012
kalpesh

Magento: Check if customer already exist or not

When trying to add new user programatically, you will need to first check whether the customer is already registered or not in the system. For that, email address is required, as Magento uses email address for login purposes.

Below is the code which checks if customer is already there in the database, with some particular website id if any.

protected function _customerExists($email, $websiteId = null)
{
    $customer = Mage::getModel('customer/customer');
    if ($websiteId) {
        $customer->setWebsiteId($websiteId);
    }
    $customer->loadByEmail($email);
    if ($customer->getId()) {
        return $customer;
    }
    return false;
}

3 Comments

  • Hello!

    I found your blog while searching for a means to check a guest email address against the existing customer database in Magento. Any insight you can offer would be appreciated.

    What I am trying to do is have the one page checkout form compare the email address entered for a guest order against the registered customer database and alert the customer that they already have an account and ask them if they would like to login before completing their order.

    Do you know if possible and/or if a solution already exists in the form of a 3rd party extension?

    Thank you for your time.

    • You need to fire ajax, or use already method which is fired, and check if customer with same address is there in DB or not. I think it should not be a big deal. And open some fancy popup saying that you are already a member, would you like to login before proceeding your order? (also provide forgot password link). If customer clicks on login before proceeding order, just close the popup and focus the cursor on login form.

      I think this should help you in building it yourself, I don’t know if there are any extensions that does this.

  • In Magento 2, How can I check if an email address is real or fake in real life?

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions