0
votes

My requirement, when the customer is registering E-mail exists validation is magento's default functionality, but we should allow the duplicate emails.

I'm using a custom module for login with username (instead of email) into magento store.

So your customization should support registration with duplicate email on front end registration/updation, back end(admin panel) registration/updation, importing from customer CSV file, And creating user from V2_API.

Please Reply me with some good solution in detailed if possible. Any help is greatly appreciated. thanks in advance.

1
Not many websites that I know of allow multiple accounts registered to the same email address. I wouldn't go through the mess, unless it is really necessary for customers to possibly have more accounts. - Lucas Moeskops

1 Answers

2
votes

Magento checked for duplicate customer email in Mage_Customer_Model_Resource_Customer class. Take a look at it. You will find this function.

protected function _beforeSave(Varien_Object $customer)
{
    parent::_beforeSave($customer);

    if (!$customer->getEmail()) {
        throw Mage::exception('Mage_Customer', Mage::helper('customer')->__('Customer email is required'));
    }

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

    // set confirmation key logic
    if ($customer->getForceConfirmed()) {
        $customer->setConfirmation(null);
    } elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
        $customer->setConfirmation($customer->getRandomConfirmationKey());
    }
    // remove customer confirmation key from database, if empty
    if (!$customer->getConfirmation()) {
        $customer->setConfirmation(null);
    }

    return $this;
}

If you are going to allow duplicate customer email, you can either comment out this 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
        );
    }

Or you'd better rewrite the customer resource. I myself recommend you to rewrite it. Hope this helps.