Magento CMS creates duplicate customer on save

We encoutered a weird issue on a website running Magento 1.9.2.2.

When saving a change on an existing customer, the Magento CMS would create a duplicate customer. Duh?

Generally magento doesn’t allow duplicate email addresses, and Magento still doesn’t! For the Dynamics Nav integration with this Magento website we edited the email check to generate a custom email by adding a date-timestamp if a duplicate email was found.

Initially we thought it happened due to the recent upgrade to magento 1.9.2.2 and the supee-65788 security changes and after some changing and testing this wasn’t the case.

The Admin customer page got some extra tabs to display and edit specific Microsoft Dynamics Nav information from the customer.

The culprit was the Navision New Comment tab.

$tempCustomer = Mage::getModel('customer/customer')
 ->getCollection()
 ->addAttributeToSelect('entity_id')
 ->addAttributeToFilter(      'nav_type','Company')
 ->load();

$customerData = $tempCustomer->getData();
$customer_id = $customerData[0]['entity_id'];

In rare occasions the ‘nav_type’ field wasn’t populated and the $customer_id returned as an empty object. This empty object would trigger the customer save function to duplicate the customer and generate a new customer entity.

Hmm. This took some time to find out and I hope this helps other Magento developers.


So, what do you think ?