具有相同id“429”的Item(Mage_Sales_Model_Quote)已经存在

时间:2015-01-12 13:33:20

标签: php magento

每当我使用sales / quote_item表加入reports / quote_collection时,我都会收到此错误。我正在尝试为未注册的用户创建一个废弃的购物车报告。我需要在废弃的购物车中显示所有商品。

请参阅以下代码:

$this->addFieldToFilter('items_count', array('neq' => '0'))
     ->addFieldToFilter('main_table.is_active', '1')
     ->addSubtotal($storeIds, $filter)
     ->setOrder('updated_at');
$this->getSelect()->joinInner(
     array('quote_items' => $this->getTable('sales/quote_item')),
            'quote_items.quote_id = main_table.entity_id',
            'name');
if (is_array($storeIds) && !empty($storeIds)) {
     $this->addFieldToFilter('store_id', array('in' => $storeIds));
}

return $this;

如何解决此错误?有没有办法显示所有项目?

1 个答案:

答案 0 :(得分:2)

当Magento尝试将同一项目两次添加到集合时会出现此消息,因为JOIN查询结果多次包含它。

您可以通过主键上的GROUP BY避免这种情况,如下所示:

$collection->getSelect()->group('e.entity_id')
相关问题