1

I know this is not ideal. But I need to try all options before moving on with this. If you have any positive advice, please feel free to drop it in a comment.

I know I can disable the validation in the PHP code but then MySQL still complains as there is a unique index on the table.

I've thought about setting up some random email addresses to at least get the users imported but this also needs to work as an ongoing process as people can still signup with a unique username and a shared branch email address.

We are limited due to a legacy system that deals with users by usernames only and multiple users/branches can share an email address.

If I hack the system for Magento it would mean that a lot of email notifications would break but this is something we could workaround.

Do you have any advice on what I can do to get this working? Have you had to deal with a similar system at all? Am I doomed to hack at the core of Magento?

2
  • 1
    Don't hack the core :) There's a Github project for just this thing. github.com/diglin/Diglin_Username Jan 27, 2015 at 18:54
  • Thanks seanbreeden, I am using the Diglin module but if you go to setup a new account with an email address that's already in the system it still complains. If I disable the validation on the email account I can use the usernames for login but then I'm not sure how stuff like email notifications will work. I appreciate the comment though, I'll stay away from hacking the core :)
    – user86790
    Jan 28, 2015 at 11:15

3 Answers 3

0

You can temporarily disable Magento checking for duplicate email addresses/customers but you're right, it's not an ideal solution by any means.

Create a local copy of /app/code/core/Mage/Customer/Resource/Model/Customer.php

Then comment out this section:

    $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
    );
}

If that gives issues try just commenting out the exception:

    if ($result) {
        throw Mage::exception(
            'Mage_Customer', Mage::helper('customer')->__('This customer email already exists'),
            Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
        );
    }

Again though, not ideal and pretty nasty really to then end up with customers with the same email address. Can't really know what issues this might cause in future!

If you can then successfully import the old customer data I'd suggest to remove the local copy so as to enable duplicate email checking again for new customers.

3
  • Thanks for the example performadigital, I'll play around with this but I think you're right, I'll use this for the legacy stuff and then see what we can do to change the how the client will handle new accounts.
    – user86790
    Jan 28, 2015 at 11:13
  • 1
    Don't forget that there's a database constraint for unique values in the customer_entity.email column as well.
    – laketuna
    Oct 2, 2015 at 22:20
  • Magento keys customer accounts on the email address. Breaking Magento's foreign key constraints will have interesting future effects. Beware the Chinese curse "May you live in interesting times." We had developers that did stuff like this on our original Magento install. They're no longer in business. Dec 6, 2015 at 6:08
-1

Using PHP? Something like this:

foreach (...) {

        $customer = Mage::getModel('customer/customer')
            ->setWebsiteId(1)
            ->loadByEmail($email);

        $customer
            ->setEmail($email)
            ->setFirstname($name)
            ...
            ->save();
    }
-1

This worked for me:

$customerObj = Mage::getModel("customer/customer");
foreach (Mage::app()->getWebsites() as $website) {
    $customerObj->setWebsiteId($website->getId());
    $customerObj->loadByEmail($customer['email']);
    if ($customerObj->getId()) {
      $message = "duplicate found" ;
      return $message;
   }

}
1
  • This does not answer the question. Feb 27, 2017 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.