Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento on Order Page: "This customer email already exists"

I imported orders into Magento using some migration tools. When a return customer tries to place an order, Magento prevents them from doing so and says "This customer email already exists." This is despite the fact that they are already logged into Magento.

Did I import/migrate into the Magento database incorrectly? Or could something else be causing this?

Any suggestions are very much appreciated.

like image 637
Isaac Y Avatar asked Jan 15 '23 04:01

Isaac Y


1 Answers

The exception you get is generated by the customer resource model's _beforeSave function, which checks if a customer with the given email address exists. The check's code:

    $adapter = $this->_getWriteAdapter();
    $bind = array('email' => $customer->getEmail());

    $select = $adapter->select()
        ->from($this->getEntityTable(), array($this->getEntityIdField()))
        ->where('email = :email');
    if ($customer->getSharingConfig()->isWebsiteScope()) {
        $bind['website_id'] = (int)$customer->getWebsiteId();
        $select->where('website_id = :website_id');
    }
    if ($customer->getId()) {
        $bind['entity_id'] = (int)$customer->getId();
        $select->where('entity_id != :entity_id');
    }
    $result = $adapter->fetchOne($select, $bind);
    if ($result) {
        throw Mage::exception(
            'Mage_Customer', Mage::helper('customer')->__('This customer email already exists'),
            Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
        );
    }

You customers are logged in, which means the condition $customer->getId() is true. But since you get an exception, I suggest, there are duplicate customer accounts with the same emails.

Can it be that your import tool has created duplicates in the customer data? That is the only reason I can think of. Check your database with this query:

 select email, count(*) from customer_entity group by email having count(*) > 1
like image 174
Oleg Ishenko Avatar answered Jan 29 '23 22:01

Oleg Ishenko