Getting fatal error on Item (Mage_Catalog_Model_Product) with the same id "223" already exist
Here 223
is my product Id
My _prepareCollection()
Method
protected function _prepareCollection()
{
$coll = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('name',array('neq'=>''))
->addAttributeToFilter('attribute_code',$this->getRequest()->getParam('my_value'));
$coll->getSelect()->join( array('order_item'=> 'mgnt_sales_flat_order_item'), 'order_item.product_id = e.entity_id', array('order_item.created_at as ocreated','order_item.qty_ordered as sales_units', 'order_item.row_total as sales_total' , 'order_item.discount_amount as discount', 'order_item.item_id as item_id' ) );
$coll->getSelect()->join( array('order'=> 'mgnt_sales_flat_order'), 'order.entity_id = order_item.order_id', array('customer_name'=>'order.customer_firstname'));
$this->setCollection($coll);
// echo $coll->getSelect();
return parent::_prepareCollection();
}
My _prepareColumns()
method
protected function _prepareColumns()
{
$this->addColumn('entity_id', array(
'header' => $this->_getHelper()->__('entity_id'),
'type' => 'text',
'index' => 'entity_id',
'filter' => false,
'sortable' => false
));
$this->addColumn('name', array(
'header' => $this->_getHelper()->__('Product Name'),
'type' => 'text',
'index' => 'name',
'filter' => false,
'sortable' => false
));
$this->addColumn('customer_name', array(
'header' => $this->_getHelper()->__('customer_name'),
'type' => 'number',
'index' => 'customer_name',
'filter' => false,
'sortable' => false
));
$this->addColumn('sales_total', array(
'header' => $this->_getHelper()->__('Sales Total'),
'type' => 'number',
'index' => 'sales_total',
'filter' => false,
'sortable' => false
));
$this->addColumn('discount', array(
'header' => $this->_getHelper()->__('Discount'),
'type' => 'number',
'index' => 'discount',
'filter' => false,
'sortable' => false
));
return parent::_prepareColumns();
}
$coll->getSelect()
any query seems to okay what I think this collection then in my result product id repetet so I think that might be issue$coll->getSelect()->group('main_table.entity_id');
groupby
if there is 100 records with sameentity_id
then I dont have a problem because that is onorder_item
basis