如何在 magento 订单网格中正确添加 shipping_description 列? [英] How to properly add a shipping_description column in magento order grid?

查看:24
本文介绍了如何在 magento 订单网格中正确添加 shipping_description 列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多教程和建议,包括安装自定义扩展等.

There are many tutorials and suggestions including installing a custom extensions etc.

我已经根据各种提示和技巧添加了 shipping_description 罚款,方法是使用以下代码修改 Grid.php,但是当按价格或状态对其进行排序时,它会引发错误:

I've added the shipping_description fine based on various tips and tricks by modifying the Grid.php with the following code, but when it comes to sorting it by Price or Status it throws an error:

SQLSTATE[23000]:违反完整性约束:1052 where 子句中的列状态"不明确或者SQLSTATE[23000]: 完整性约束违规: 1052 where 子句中的列 'increment_id' 不明确

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous or SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'increment_id' in where clause is ambiguous

不过,按帐单和发货名称排序没问题.

It sorts ok by Billing and Shipping Name though.

在 Grid.php 中添加了以下代码:

The following code was added to Grid.php:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $tableName = Mage::getSingleton("core/resource")->getTableName('sales_flat_order');                  
    $collection->getSelect()->join($tableName, "main_table.entity_id =          $tableName.entity_id",array("shipping_description"));
    $this->setCollection($collection);               
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}     


protected function _prepareColumns()
{
    $this->addColumnAfter('shipping_description', array(
        'header'    => Mage::helper('sales')->__('Delivery'),
        'width'     => '180px',
        'type'      => 'text',
        'index'     => 'shipping_description'

    ),'shipping_name');   

    return parent::_prepareColumns();
} 

任何想法,想法将不胜感激!!!

any thoughts, ideas would be appreciated!!!

推荐答案

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

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.

这篇关于如何在 magento 订单网格中正确添加 shipping_description 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆