magento 后台订单列表显示商品名称/SKU

113225_j5uG_1412997.png

修改 app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php (创建文件)

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $this->setCollection($collection);
    $orderitemtable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
    $collection->getSelect()
         ->join(
            $orderitemtable,"`main_table`.`entity_id`=`$orderitemtable`.`order_id`",
            array(
                'sku'  => new Zend_Db_Expr("group_concat(`$orderitemtable`.sku SEPARATOR ', ')"),
                'name' => new Zend_Db_Expr("group_concat(`$orderitemtable`.name SEPARATOR ', ')"),
                'is_virtual'
            )
        )
        ->group("main_table.entity_id");

    return parent::_prepareCollection();
}


protected function _prepareColumns()
{

    $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('name', array(
        'header' => Mage::helper('sales')->__('Productname'),
        'index' => 'name',
    ));


    $this->addColumn('skus', array(
        'header' => Mage::helper('sales')->__('SKU'),
        'index' => 'skus',
    ));

    $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();
}


参考 http://stackoverflow.com/questions/15586816/add-sku-column-magento-admin-sales-order

转载于:https://my.oschina.net/xinson/blog/491131

你可能感兴趣的:(magento 后台订单列表显示商品名称/SKU)