A couple of days back I posted a question on StackExchange - Magento. Please read that post as this question is related.
Since, I wanted to have this newly created customer attribute Unique. i.e no user should have same attribute as another already existing user. I tried doing it my self this way :
I've modified the _beforeSave()
function in /core/Mage/Customer/Model/Resource/Customer.php
by adding the following code right before email verification logic.
$result=Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('mobile', $customer->getMobile())->load();
if ( is_object($result) && count($result) >= 1)
{
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('There is already an account with this mobile number.'),
Mage_Customer_Model_Customer::EXCEPTION_MOBILE_EXISTS
);
}
Doing so, I was able to throw an exception when the attribute is already associated with an existing user.
Is adding required code to Model a good idea ? Will this modification stay intact if I update Magento from admin panel ?
Also, please suggest (if any) an alternative solution to check for duplicate entry in my local module rather than editing a core Model file.