Magento 1.9.x trying to save $customer data => "Uncaught Mage_Customer_Exception: This customer email already exists"

We are looping thru all customers, updating data and saving

Only when saving a customer with an email that already exists: we see the error Uncaught Mage_Customer_Exception: This customer email already exists

Although when I check Magento the email does exist twice, but in different stores. So it should! save the customer, nothing is wrong

Question: how can we prevent this from happening?

We are looping data as follows

$customers = mage::getModel('customer/customer')->getCollection()

$cnt_me = 0;
foreach ($customers as $customer) {
    $data = array();
    $customer_id = $customer->getId();
    $customer_name = $customer->getName();
    $customer_email = $customer->getEmail();
    $orders = Mage::getModel('sales/order')->getCollection()
        ->addFieldToFilter('customer_id', $customer_id)
        ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()));
    foreach ($orders as $order) {
        foreach ($order->getAllItems() as $item) 


then later we do the following

if ($save) {
    $this->_dataSaveAllowed = true;
} else {
  • Did you check website id? or your settings is global for all store? – Sohel Rana May 10 '19 at 18:53
  • Update question with full code. – Sohel Rana May 10 '19 at 18:57

You need to do following things.


$store = Mage::getModel('core/store')->load($store_Id);

$customers = Mage::getModel('customer/customer')->getCollection()

foreach ($customers as $customer) 
| improve this answer | |

The solution is to : double (yes double) check if there is max 1 account per email per store.

In our case somehow customers were created with store is admin, but storeview is the same as a store where the user already existed.

So the solution was to clean the data and make absolutely certain there are no duplicate emails

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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