use*_*945 8 join magento magento-1.7
我已经解决了这个问题,最后!
基本上,我越来越WHERE部分用$where = $select->getPart('where')
,然后我经过每一个条件和搜索created_at
,如果我觉得有匹配的I替换created_at
用main_table.created_at
.
我已经对此进行了测试,一切正常,如果有什么东西可以"越野车"请告诉我.
谢谢大家!!
public function salesOrderGridCollectionLoadBefore($observer)
{
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$select->joinLeft(array('custab' => 'my_custom_table'), 'main_table.entity_id = custab.order_id',array('custab.field_to_show_in_grid'));
if ($where = $select->getPart('where')) {
foreach ($where as $key=> $condition) {
if (strpos($condition, 'created_at')) {
$new_condition = str_replace("created_at", "main_table.created_at", $condition);
$where[$key] = $new_condition;
}
}
$select->setPart('where', $where);
}
Run Code Online (Sandbox Code Playgroud)
}
我正在尝试使用observer从自定义表中添加销售订单网格中的新列.一切正常,直到我尝试使用列过滤网格created_at
.
问题是因为我created_at
在自定义表和sales_flat_order_grid
表中有相同的列名().
我收到了这个错误
SQLSTATE [23000]:完整性约束违规:1052 where子句中的'created_at'列不明确
如果我将此行编辑'index' => 'created_at'
为
'index' => '**main_table**.created_at'
,inapp/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'main_table.created_at',
'type' => 'datetime',
'width' => '100px',
));
Run Code Online (Sandbox Code Playgroud)
一切正常,但我不想更改核心文件或将它们复制到本地文件夹和编辑,我认为有一些简单的解决方案,我需要添加到我的观察者.
这是我的Observer.php
class Testinggrid_ExtendOrderGrid_Model_Observer{
public function salesOrderGridCollectionLoadBefore($observer)
{
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$select->joinLeft(array('custab' => 'my_custom_table'), 'main_table.entity_id = custab.order_id',array('custab.field_to_show_in_grid'));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模块布局
<layout>
<sales_order_grid_update_handle>
<reference name="sales_order.grid">
<action method="addColumnAfter">
<columnId>field_to_show_in_grid</columnId>
<arguments>
<header>Column header</header>
<index>field_to_show_in_grid</index>
<filter_index>field_to_show_in_grid</filter_index>
<type>text</type>
</arguments>
<after>shipping_name</after>
</action>
</reference>
</sales_order_grid_update_handle>
<adminhtml_sales_order_grid>
<!-- apply layout handle defined above -->
<update handle="sales_order_grid_update_handle" />
</adminhtml_sales_order_grid>
<adminhtml_sales_order_index>
<!-- apply layout handle defined above -->
<update handle="sales_order_grid_update_handle" />
</adminhtml_sales_order_index>
</layout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5345 次 |
最近记录: |