2

我正在尝试按 Sku 和产品名称扩展销售-> 订单网格。

我设法在所有数据的网格中获取 sku 和名称。

现在的问题是它打破了分页。

谁能帮我解决这个问题。

代码:

        class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
    {

        public function __construct()
        {
            parent::__construct();
            $this->setId('sales_order_grid');
            $this->setUseAjax(true);
            $this->setDefaultSort('created_at');
            $this->setDefaultDir('DESC');
            $this->setSaveParametersInSession(true);
        }

        /**
         * Retrieve collection class
         *
         * @return string
         */
        protected function _getCollectionClass()
        {
            return 'sales/order_grid_collection';
        }

        protected function _prepareCollection()
        {

// Custom code
            $collection = Mage::getResourceModel($this->_getCollectionClass())
                            ->join(
                    'sales/order_item',
                    '`sales/order_item`.order_id=`main_table`.entity_id',
                    array(
                        'sku'  => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
                        'name' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
                        )
                    );
                    $collection->getSelect()->group('entity_id');
            $this->setCollection($collection);
            return parent::_prepareCollection();
        }

        protected function _prepareColumns()
        {

// Custom code
            $this->addColumn('name', array(
                'header'    => Mage::helper('Sales')->__('Name'),
                'width'     => '100px',
                'index'     => 'name',
                'type'        => 'text',
            ));

            $this->addColumn('sku', array(
                'header'    => Mage::helper('Sales')->__('Sku'),
                'width'     => '100px',
                'index'     => 'sku',
                'type'        => 'text',

            ));
            $this->addColumn('real_order_id', array(
                'header'=> Mage::helper('sales')->__('Order #'),
                'width' => '80px',
                'type'  => 'text',
                'index' => 'increment_id',
            ));

            if (!Mage::app()->isSingleStoreMode()) {
                $this->addColumn('store_id', array(
                    'header'    => Mage::helper('sales')->__('Purchased From (Store)'),
                    'index'     => 'store_id',
                    'type'      => 'store',
                    'store_view'=> true,
                    'display_deleted' => true,
                ));
            }

            $this->addColumn('created_at', array(
                'header' => Mage::helper('sales')->__('Purchased On'),
                'index' => 'created_at',
                'type' => 'datetime',
                'width' => '100px',
            ));

            $this->addColumn('billing_name', array(
                'header' => Mage::helper('sales')->__('Bill to Name'),
                'index' => 'billing_name',
            ));

            $this->addColumn('shipping_name', array(
                'header' => Mage::helper('sales')->__('Ship to Name'),
                'index' => 'shipping_name',
            ));

            $this->addColumn('base_grand_total', array(
                'header' => Mage::helper('sales')->__('G.T. (Base)'),
                'index' => 'base_grand_total',
                'type'  => 'currency',
                'currency' => 'base_currency_code',
            ));

            $this->addColumn('grand_total', array(
                'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
                'index' => 'grand_total',
                'type'  => 'currency',
                'currency' => 'order_currency_code',
            ));

            $this->addColumn('status', array(
                'header' => Mage::helper('sales')->__('Status'),
                'index' => 'status',
                'type'  => 'options',
                'width' => '70px',
                'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
            ));

            if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
                $this->addColumn('action',
                    array(
                        'header'    => Mage::helper('sales')->__('Action'),
                        'width'     => '50px',
                        'type'      => 'action',
                        'getter'     => 'getId',
                        'actions'   => array(
                            array(
                                'caption' => Mage::helper('sales')->__('View'),
                                'url'     => array('base'=>'*/sales_order/view'),
                                'field'   => 'order_id'
                            )
                        ),
                        'filter'    => false,
                        'sortable'  => false,
                        'index'     => 'stores',
                        'is_system' => true,
                ));
            }
            $this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));

            $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
            $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));

            return parent::_prepareColumns();
        }

问题出在我的收藏上。我在这里使用核心课程,但一旦我得到我的结果,我会覆盖它。

4

1 回答 1

1

GROUP BY您的集合中有一个子句,网格寻呼机用于$collection->getSize()确定页数。问题是getSize()将 a 应用于SELECT COUNT(*)集合,并获取第一行的第一列以获取结果数。在GROUP BY仍然应用的情况下,寻呼机然后认为只有一个结果。

为防止出现此问题,您应该使用您自己的带有相关的订单集合getSize(),或者使用子查询来检索 SKU 和名称。

于 2013-08-12T08:52:11.857 回答