I'm trying to extend Products in carts report grid. I needed to separate products for each customer and add a Customer name column. So for example a product with id
number equal to 123
may exist in two different carts which means for two individual customers. So I need two rows for product id=123
.
But at the moment when this happens I get a familiar message:
Item (Mage_Sales_Model_Quote) with the same id "123" already exist
I tried to rewrite my query starting from sales_flat_quote_item
as main table (to have unique entities) but since I'm extending Mage_Reports_Model_Resource_Quote_Collection
this fails with this error message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.entity_id'
in 'field list', query was: SELECT STRAIGHT_JOIN COUNT(DISTINCT main_table.entity_id)
FROM `sales_flat_quote_item` AS `main_table` ...
Currently my prepareForProductsInCarts
function starts with:
$collection = Mage::getResourceSingleton('sales/quote_item_collection');
and ends with:
// reset methods may be redundant
$this->getSelect()
->useStraightJoin(true)
->reset(Zend_Db_Select::COLUMNS)
->reset(Zend_Db_Select::DISTINCT)
->reset(Zend_Db_Select::GROUP)
->reset(Zend_Db_Select::WHERE);
$this->getSelect()->setPart(Zend_Db_Select::COLUMNS, $collection->getSelect()->getPart(Zend_Db_Select::COLUMNS));
$this->getSelect()->setPart(Zend_Db_Select::FROM, $collection->getSelect()->getPart(Zend_Db_Select::FROM));
$this->getSelect()->setPart(Zend_Db_Select::GROUP, $collection->getSelect()->getPart(Zend_Db_Select::GROUP));
$this->getSelect()->setPart(Zend_Db_Select::WHERE, $collection->getSelect()->getPart(Zend_Db_Select::WHERE));
What can I do to allow or work around duplicated entities?