覆盖Adminhtml销售订单网格(Magento 1.x)

时间:2018-03-13 06:56:50

标签: magento magento-1.7

我想在Magento管理员中覆盖销售订单网格。我为此创建了自定义模块,但似乎我的覆盖不起作用。没有错误。

请在上面找到我的代码:

应用的/ etc /模块/

<config>
<modules>
    <Bikebear_SalesGrid>
        <active>true</active>
        <codePool>local</codePool>
    </Bikebear_SalesGrid>
</modules>

应用程序/代码/本地/ Bikebear / SalesGrid /等

<config>    
<modules>
    <Bikebear_SalesGrid>
        <version>1.0.0</version>
    </Bikebear_SalesGrid>
</modules>  
<global>
    <blocks>
        <ordergrid>
            <class>Bikebear_SalesGrid_Block</class>
        </ordergrid>
        <adminhtml>
            <rewrite>
                <sales_order_grid>Bikebear_SalesGrid_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
            </rewrite>
        </adminhtml>
    </blocks>
</global>       

的应用程序/代码/本地/ Bikebear / SalesGrid /砌块/ Adminhtml /销售/订单

class Bikebear_SalesGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {

protected function _prepareCollection(){
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $this->setCollection($collection);
    return $this;
}

protected function _prepareColumns()
{
    $this->addColumn('real_order_id', array(
        'header'=> Mage::helper('sales')->__('Order #'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'increment_id',
    ));
    $this->addColumn('postcode', array(
        'header' => Mage::helper('sales')->__('Postcode 1'),
        'index' => 'postcode',
    ));
    if (!Mage::app()->isSingleStoreMode()) {
        $this->addColumn('store_id', array(
            'header'    => Mage::helper('sales')->__('Purchased From (Store)'),
            'index'     => 'store_id',
            'type'      => 'store',
            'store_view'=> true,
            'display_deleted' => true,
        ));
    }

    $this->addColumn('created_at', array(
        'header' => Mage::helper('sales')->__('Purchased On'),
        'index' => 'created_at',
        'type' => 'datetime',
        'width' => '100px',
    ));

    /*$this->addColumn('billing_name', array(
        'header' => Mage::helper('sales')->__('Bill to Name'),
        'index' => 'billing_name',
    ));*/

    $this->addColumn('shipping_name', array(
        'header' => Mage::helper('sales')->__('Ship to Name'),
        'index' => 'shipping_name',
    ));

    /*$this->addColumn('base_grand_total', array(
        'header' => Mage::helper('sales')->__('G.T. (Base)'),
        'index' => 'base_grand_total',
        'type'  => 'currency',
        'currency' => 'base_currency_code',
    ));*/

    $this->addColumn('grand_total', array(
        'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
        'index' => 'grand_total',
        'type'  => 'currency',
        'currency' => 'order_currency_code',
    ));

    $this->addColumn('status', array(
        'header' => Mage::helper('sales')->__('Status'),
        'index' => 'status',
        'type'  => 'options',
        'width' => '70px',
        'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
    ));
    return parent::_prepareColumns();
}}

我做错了什么,为什么没有结果?提前谢谢。

3 个答案:

答案 0 :(得分:0)

您可以使用 app / code / local / Bikebear / SalesGrid / Block / Adminhtml / Sales / Order

中的以下代码替换 _prepareCollection()函数
protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

或者您可以尝试使用以下代码

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('sales/order_grid_collection');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

希望它会有所帮助。

答案 1 :(得分:0)

谢谢大家的帮助,我已经解决了这个问题。

问题是另一个模块在那里调用,所以我在那个模块上进行了更改。

由于

答案 2 :(得分:0)

您可以在_prepareCollection函数中添加

return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();

所以根据您的函数,代码应该像这样

protected function _prepareCollection(){
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $this->setCollection($collection);
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}

希望它会对您有所帮助:)