2015-05-18 45 views
0

几天前我发布了question on StackExchange - Magento。请阅读该帖子,因为这个问题是相关的。是不是一个好主意,修改Magento Cutomer模型

因为我想让这个新创建的客户属性Unique。即没有用户应该具有与另一个已经存在的用户相同的属性。我试图用这种方式做我自己:

我已经修改函数/core/Mage/Customer/Model/Resource/Customer.php通过添加以下代码电子邮件验证逻辑之前。

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

这样做,当属性已经与现有用户相关联时,我能够引发异常。

添加所需的代码来建模一个好主意?如果我从管理面板更新Magento,这种修改会保持不变吗?

此外,请建议(如果有)替代解决方案来检查我的本地模块中的重复条目,而不是编辑核心模型文件。

回答

相关问题