2015-05-18 40 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,這種修改會保持不變嗎?

此外,請建議(如果有)替代解決方案來檢查我的本地模塊中的重複條目,而不是編輯核心模型文件。

回答

相關問題