首页 > 代码库 > Item with the same id "98" already exist

Item with the same id "98" already exist

在magento项目中多次遇到这样一个错误:

Item (Bluecom_Onefieldusername_Model_Customer) with the same id "98" already exist

解决方案:

(1) 新建一个类,必须继承Varien_Object

 

class Mypackage_Mymodule_Model_UniqueId extends Varien_Object{    public function getUniqueNumber(){        list($usec, $sec) = explode(" ", microtime());        return uniqid(mt_rand().$sec.($usec*1000000));    }    public function getId(){        return $this->getUniqueNumber();    }}

 

(2)在getCollection后面使用setItemObjectClass(‘mymodule/uniqueId‘)

 

Item with the same id "98" already exist