Magento Sales Order Grid shows incorrect number of records when added Names and Skus columns

China☆狼群 提交于 2019-12-04 08:12:17

Maybe its a bit to late but in your code try using GROUP insted of HAVING:

$countSelect->reset(Zend_Db_Select::GROUP);

Because you are using this statemen:

$collection->getSelect()->group('entity_id');
$collection->getSelect()->join(array(
            'item'=>$collection->getTable('sales/order_item')),
            'item.order_id=`main_table`.entity_id AND item.product_type="simple"',
            array(
                'skus' => new Zend_Db_Expr('group_concat(item.sku SEPARATOR ", ")'),
                'name' => new Zend_Db_Expr('group_concat(item.name SEPARATOR ", ")')
            ));

$this->addColumn('skus', array(
            'header' => Mage::helper('sales')->__('SKU'),
            'index' => 'skus',
            'type' => 'text',
        ));

        $this->addColumn('name', array(
            'header' => Mage::helper('sales')->__('NAME'),
            'index' => 'name',
            'type' => 'text'
        ));

I had this issue and i have got it working by implementing custom getSize() function in the collection i am using

public function getSize()
{
    $select = clone $this->getSelect();
    $select->reset();
    $select =  $this->getConnection()->fetchOne('SELECT COUNT(*) FROM Table GROUP BY FIELD'); // or you can use select count(distinct field) from table
    return $select;
}

and to achieve Grid storing i have override

protected function _setCollectionOrder($column)
    {
        $collection = $this->getCollection();
        if ($collection) {
            $columnIndex = $column->getFilterIndex() ?
                $column->getFilterIndex() : $column->getIndex();
            $collection->getSelect()->order(array($columnIndex.' '.$column->getDir()));
        }
        return $this;
    }

and Set filter_index of the columns TO

 in _prepareColumns() function 
    'filter_index' => 'SUM(tablename.field)'

and you can use Callback function on filters for the columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!