Item (Mage_Catalog_Model_Product) with the same id ”xxx“ already exist

来源:互联网 发布:搜狗手机输入法mac 编辑:程序博客网 时间:2024/06/06 01:36

Step 1. Modify the core file lib/Varien/Data/Collection.php, function addItem(), but unlike this answer suggests, don't hide the error.

Instead, add extra error information to the exception thrown:

        if (isset($this->_items[$itemId])) {            throw new Exception('Item ('.get_class($item).                ') with the same id "'.$item->getId().'" already exist' .                '. SQL that caused this: ' . $this->getSelect());        }

Step 2. Take the offending query from your error report and run it by hand. See what records duplicate the collection key. Addorder by <key field> as needed.

Dissect the query removing the participating tables one-by-one, and see which record caused the duplication.

I believe this patch should be in the core.



lib\Varien\Data\Collection.php

注释掉,未解决实际问题

    public function addItem(Varien_Object $item)    {        $itemId = $this->_getItemId($item);        if (!is_null($itemId)) {//            if (isset($this->_items[$itemId])) {//                throw new Exception('Item ('.get_class($item).') with the same id "'.$item->getId().'" already exist');//            }//            if (isset($this->_items[$itemId])) {//                throw new Exception('Item ('.get_class($item).//                    ') with the same id "'.$item->getId().'" already exist' .//                    '. SQL that caused this: ' . $this->getSelect());//            }            $this->_items[$itemId] = $item;        } else {            $this->_addItem($item);        }        return $this;    }




编译之后需要对下列文件处理

includes\src\__default.php

\includes\src\Varien_Data_Collection.php

\includes\src\Varien\Data\Collection.php

0 0
原创粉丝点击