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()
->addNameToSelect();
$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;
$customer->save();
} else {
continue;
}