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

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

问题描述

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

我通过修改Grid.php添加了基于各种提示和技巧的shipping_description罚款使用下面的代码,但是当涉及到按价格或状态进行排序时,它会抛出一个错误:



SQLSTATE [23000]:完整性约束冲突:1052列'状态'在where子句中不明确

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



它排序

以下代码已添加到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();


$ b保护函数_prepareColumns()
{
$ this-> addColumnAfter('shipping_description',array(
'header '=> Mage :: helper('sales') - > __('Delivery'),
'width'=>'180px',
'type'=>'text' ,
'index'=>'shipping_description'

),'shipping_name');

返回parent :: _ prepareColumns();
}

任何想法,想法都将被赞赏!!!

解决方案

下面的例子适用于我的案例。排序现在适用于每一个领域。没有核心文件被覆盖。



一步一步地处理同一船上的人。测试在1.8.1


  1. 将您的Grid.php从

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



    如果路径不存在,请创建它。

  2. 打开您的新的Grid.php并将以下代码添加到 getResourceModel 行后面的 _prepareCollection()

    $ 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' );


  3. 将以下代码添加到 _prepareColumns()在你想要的 addColumn()调用之间)

    $ this-> addColumn('shipping_description',array(
    'header'=> Mage :: helper('sales') - > __('Delivery'),
    'type'=> 'text',
    'index'=> 'shipping_description',

    'filter_index'=> 'mt.shipping_description',
    ));


  4. 查找 addColumns() code> increment_id,store_id,created_at,base_grand_total,grand_total,status 中的code>函数,并在每个函数中添加以下参数:

    'filter_index'=> 'mt .___ your_column_name ____',


有关如何优化上述代码的任何建议, 。


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

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]: 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.

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.

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

  1. Copy your Grid.php from

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

    if the path doesn't exist create it.

  2. 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');

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

    $this->addColumn('shipping_description', array( 'header' => Mage::helper('sales')->__('Delivery'), 'type' => 'text', 'index' => 'shipping_description',
    'filter_index' => 'mt.shipping_description', ));

  4. 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天全站免登陆