你可以帮帮我吗?我正在尝试使用观察者将新列添加到管理员的订单网格中。有我的 config.xml
<adminhtml>
<events>
<adminhtml_block_html_before>
<observers>
<order_grid>
<type>model</type>
<class>Order_Grid_Model_Observer</class>
<method>addItemsColumn</method>
</order_grid>
</observers>
</adminhtml_block_html_before>
</events>
</adminhtml>
有我的观察者代码:
class Order_Grid_Model_Observer
{
public function addItemsColumn($observer)
{
$_block = $observer->getBlock();
$_type = $_block->getType();
if ($_type == 'adminhtml/sales_order_grid') {
$_block->addColumn('total_item_count', array(
'header'=> Mage::helper('sales')->__('Items'),
'width' => '80px',
'type' => 'text',
'index' => 'total_item_count',
'sortable' => false,
'filter' => false
));
$_block->getColumn('real_order_id')
->setData('filter_index', 'main_table.increment_id');
$collection = $_block->getCollection();
$collection->clear();
$collection->getSelect()
->joinLeft(array('o' => 'sales_flat_order'), 'o.entity_id = main_table.entity_id', array('total_item_count'));
$_block->setCollection($collection);
}
}
}
我几乎做到了,但是当我尝试按某个字段对网格进行排序时,我收到错误“字段列表中的列'increment_id'不明确”。这很奇怪,因为我已经为“increment_id”字段更新了“filter_index”。任何想法为什么这个块的集合没有更新?谢谢。