覆盖了矩阵顺序网格后,分页不起作用?

问题描述 投票:1回答:1

我重写了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...

但是分页不起作用。所有记录都加载在单个页面中。请提出任何建议?

php magento-1.7
1个回答
5
投票

找到解决方案。

由于以下陈述而发生了该问题。

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

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

位于app/code/local/Varien/Data/Collection/Db.php的My 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

然后清除了缓存和会话后,它就起作用了..:)

© www.soinside.com 2019 - 2024. All rights reserved.