0
votes

Got this code (in: app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php):

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR "<br>")')))->group('sales_flat_order_item.entity_id');
        $collection->getSelect()->join('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'))->group('sales_flat_order_payment.parent_id');
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

When I comment the line below COL 1 or COL 2 this works fine, but I want them to work both, how is this done? (if I use them at the same time I get an error: Integrity constraint violation: 1052 Column 'entity_id' in group statement is ambiguous)

UPDATE WITH ANSWER:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR "<br>")')));
    $collection->getSelect()->join('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'))->group('main_table.entity_id');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
2

2 Answers

2
votes

The answer is in the error, the table to apply the group to cannot be determined. You need to explicitly define the table:

...->group('sales_flat_order_item.entity_id');
0
votes

echo your query by using echo (string) $collection->getSelect(); You will get a plain sql query here. Fire that query in database and check, are you getting results the way you want. Also last but not the least Group also create problem. Have a look at below link using group() breaks getSelectCountSql in magento