Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Altering Sales Grid Breaks Pagination
 
kimball1
Jr. Member
 
Total Posts:  11
Joined:  2011-04-02
 

Our sales fulfillment staff wanted to see different columns in the sales grid to make fulfilling orders easier.  After doing a bunch of research and finding similar changes others had made, I copied:
app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
to
app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

Then I altered the new local copy of Grid.php to have a totally new _prepareCollection() as follows:

protected function _prepareCollection()
    
{
        $separatorStyle 
"border:0;border-bottom:1px dashed #aaa;";
        
$collection Mage::getResourceModel($this->_getCollectionClass())
            ->
join(
                
'sales/order_item',
                
'`sales/order_item`.order_id=`main_table`.entity_id',
                array(
                    
'skus'  => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR "<BR><BR>")'),
                    
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR "<BR><BR>")'),
                    )
                );
                
                
$collection->getSelect()->group('main_table.entity_id');

                
$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),
                
'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight',
                
'sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status',
                
'sfo.base_grand_total','sfo.grand_total''sfo.base_shipping_amount'));
                
                
 
            
$this->setCollection($collection);
        return 
parent::_prepareCollection();
    
}

Then I altered prepareColumns() to handle the new columns from the above _prepareCollection() (I’d paste that method here as well, but it is too large for a forum post.)

After making these changes, the new fields appear in the grid on the sales->Orders grid, and the fulfillment staff began to sing my praises.  However, this also broke the pagination.  Our store has well over 10k orders over the years, but if you go to the sales->Orders grid, the pagination always shows page 1 of 1.  If you select to show 50 orders per page, it loads and shows 50 orders, indicating page 1 of 1.  If you tell it to show 200 orders per page, it shows 200 orders, indicating page 1 of 1.

If I revert my local changes to match the original core Grid.php, the pagination works as expected, but of course then my custom fields are removed from the grid.

How do I get it to paginate correctly with custom fields in that grid?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
roshanlal
Member
 
Avatar
Total Posts:  33
Joined:  2010-01-15
india
 

Hi kimball1,

Please remove group() method. I hope this will solve your problem.

When you use group by Magento call the method

public function getSize()
    
{
        
if (is_null($this->_totalRecords)) {
            $sql 
$this->getSelectCountSql();
            
$this->_totalRecords $this->getConnection()->fetchOne($sql$this->_bindParams);
        
}
        
return intval($this->_totalRecords);
    
}

you can find this in the library, Varien_Data_Collection_Db

In the If you use count() with group by you’ll get a result containing the number of items for each group.

Also you can follow this thread: http://www.magentocommerce.com/boards/viewthread/51137/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top