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

How to properly add a shipping_description column in magento order grid?(如何在 magento 订单网格中正确添加 shipping_description 列?)
本文介绍了如何在 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 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)