私たちを手伝ってくれますか?オブザーバーを使用して、管理者の注文グリッドに新しい列を追加しようとしています。私の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'を更新したので、奇妙です。このブロックのコレクションが更新されなかった理由はありますか?ありがとう。