将列添加到管理>销售>订单网格


Answers:


20

Inchoo 在扩展订单网格方面写了一篇很棒的文章。在Atwix博客上,有一篇文章介绍了如何从其他表添加列。

Inchoo博客文章基本上通过自定义扩展对其进行了扩展。如果您不熟悉编写自己的扩展程序,建议您参考Alan Storms教程Magento 4U的教程

您将重写Mage_Adminhtml_Order_Grid块类,在_prepareColumns方法中添加一列,并_prepareCollection使用您的自定义字段扩展方法


7

它是一个两步简单的过程。(例如,我想在此订单网格中添加电子邮件地址和订单城市)。
将此核心文件首先复制到本地同一目录中。app / code / core / Mage / Adminhtml / Block / Sales / Order / Grid.php

步骤1:在函数_prepareColumns()中添加以下代码行

$this->addColumn('email', array(
        'header'    => Mage::helper('catalog')->__('Customer Email'),
        'index'     => 'email',
        'type' => 'text'
    ));
$this->addColumn('city', array(
        'header'    => Mage::helper('catalog')->__('Order From City'),
        'index'     => 'city',
        'type' => 'text'
    ));

步骤2:在函数_prepareCollection()中添加以下代码行

$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id' ,array('email'=> 'email', 'city'=> 'city' ));
$collection->addFieldToFilter('sales_flat_order_address.address_type', array('eq' => 'billing'));

整体查询将类似于:

选择main_table。* 、sales_flat_order_address. emailAS customer_emailsales_flat_order_addresscitysales_flat_order_grid作为内部main_table联接的sales_flat_order_addressmain_table.entity_id = sales_flat_order_address.parent_id在哪里(sales_flat_order_address.address_type ='billing')

根据需要修改代码。
希望能有所帮助。



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.