在覆盖了magento顺序网格之后,分页就不起作用了


After overriding the magento order grid, pagination is not working?

我重写了Mage_Adminhtml_Block_Sales_Order_Grid,添加了3列,如下所示。

  1. 客户电子邮件
  2. 付款类型
  3. 订购的产品

我的扩展网格类如下。

<?php
class Wowmall_ExtendedGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
    protected function _getCollectionClass()
    {
        return 'sales/order_grid_collection';
    }
    protected function _prepareCollection()
    {   
       $collection = Mage::getResourceModel($this->_getCollectionClass());
       $collection->getSelect()
                   ->joinLeft('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id','method')
                   ->join('customer_entity', 'main_table.customer_id = customer_entity.entity_id','email')
                   ->join('sales_flat_order_item', 'main_table.entity_id = sales_flat_order_item.order_id','name')->distinct(true);
         $collection->getSelect()->group('main_table.entity_id');
         $this->setCollection($collection);
        return $this;
    }
    protected function _prepareColumns()
    {
       // rest code...
        $this->addColumn('email', array(
            'header' => Mage::helper('sales')->__('Customer Email'),
            'index' => 'email',
            'type' => 'text',
        ));
        $this->addColumn('method', array(
        'header'    => Mage::helper('sales')->__('Payment Type'),
        'index'     => 'method',
        'type'      => 'options',
        'options'   => array('verisign' => 'Credit Card', 'checkmo' => 'Check', 'purchaseorder' => 'Purchase Order'),
    ));
         $this->addColumn('name', array(
            'header' => Mage::helper('sales')->__('Product(s) Ordered'),
            'index' => 'name',
            'type' => 'text',
        ));
       // rest code...

但是分页不起作用。所有记录都加载在一个页面中。有什么建议吗?

找到了解决方案。

出现此问题的原因如下。

$collection->getSelect()->group('main_table.entity_id');

我编辑了lib/Varien/Data/Collection/Db.php

我的Db.php文件位于app/code/local/Varien/Data/Collection/Db.php

以下是代码。

.....//rest code
public function getSelectCountSql()
    {
        $this->_renderFilters();
        $countSelect = clone $this->getSelect();
        $countSelect->reset(Zend_Db_Select::ORDER);
        $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
        $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
        $countSelect->reset(Zend_Db_Select::COLUMNS);
        if(count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
            $countSelect->reset(Zend_Db_Select::GROUP);
            $countSelect->distinct(true);
            $group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
            $countSelect->columns("COUNT(DISTINCT ".implode(", ", $group).")");
        } else {
            $countSelect->columns('COUNT(*)');
        }
        return $countSelect;
    }
....//rest code

然后在清除缓存和会话后,它工作了..:)