且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 magento 订单网格中正确添加 shipping_description 列?

更新时间:2023-11-29 21:36:04

以下在我的情况下有效.排序现在适用于每个字段.没有覆盖核心文件.

The following worked in my case. Sorting now works from every single field. No core files overridden.

步步为营的人.在 1.8.1 中测试

Step by step for someone who is in the same boat. Tested in 1.8.1

/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php 到/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

如果路径不存在,则创建它.

if the path doesn't exist create it.

打开新的 Grid.php 并将以下代码添加到 getResourceModel 行之后的 _prepareCollection() 中:

Open your new Grid.php and add the following code into _prepareCollection() after getResourceModel line:

$collection->getSelect()->join(array('mt'=>'sales_flat_order'),'mt.entity_id = main_table.entity_id',array('mt.increment_id','mt.store_id','mt.created_at','mt.shipping_description','mt.status','mt.base_grand_total','mt.grand_total'));

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

将以下代码添加到 _prepareColumns() 函数中(在所需的 addColumn() 调用之间)

Add the following code into _prepareColumns() function (in between your desired addColumn() calls)

$this->addColumn('shipping_description', array('标题' =>Mage::helper('sales')->__('Delivery'),'类型' =>'文本','索引' =>'shipping_description',
'filter_index' =>'mt.shipping_description',));

increment_id、store_id、created_at、base_grand_total、grand_total、status 找到 addColumns() 函数,并在每个函数中添加以下参数:

Find addColumns() functions for increment_id, store_id, created_at, base_grand_total, grand_total, status and add the following argument in each:

'filter_index' =>'mt.___your_column_name____',

欢迎任何关于如何优化上述代码的建议.

Any suggestion on how to optimise above code are welcome.