1

I have overridden the Mage_Adminhtml_Block_Sales_Order_Grid to add additionl 3 columns as follows.

  1. Customer Email
  2. Payment Type
  3. Products ordered

My extended grid class is as follows.

<?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...

But the pagination is not working. All the records are loading in a single page. Please any suggestions?

4

1 回答 1

5

找到了解决方案。

该问题是由于以下声明而发生的。

$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

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

于 2013-07-03T07:13:46.333 回答