4

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

4

1 に答える 1

5

「私たち」(別のグループ)は、 Magento Hackathonに拡張機能を実装しました。これにより、新しい列を簡単に追加、再配置、グリッドから列を削除できます。さらに、テーブルをコレクションに結合して列を追加できます。

https://github.com/magento-hackathon/GridControl

于 2012-12-12T08:06:04.537 に答える