【问题标题】:Override Adminhtml Sales Order Grid (Magento 1.x)覆盖 Adminhtml 销售订单网格 (Magento 1.x)
【发布时间】:2018-03-13 06:56:50
【问题描述】:

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

请在上面找到我的代码:

app/etc/modules/

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

app/code/local/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>       

app/code/local/Bikebear/SalesGrid/Block/Adminhtml/Sales/Order

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();
}}

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

【问题讨论】:

  • 首先,覆盖这个网格的目的是什么?你想用它做什么?您是否只想隐藏示例中的几列?在 Magento 中,覆盖不是一个好的做法,在大多数情况下,您可以使用观察者。请建议您想做什么,我可以尽力帮助您。谢谢。
  • 实际上我想隐藏“base_grand_total”和“billing_name”,我想为“送货地址”和“交货日期”添加新列。请帮助我,请让我知道如何实现这一目标。谢谢

标签: magento magento-1.7


【解决方案1】:

您可以在 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();
}

希望它会有所帮助。

【讨论】:

  • 我已经尝试过了,但它同样没有调用它。
【解决方案2】:

谢谢大家的帮助,我已经解决了。

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

谢谢

【讨论】:

    【解决方案3】:

    你可以在_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();
    }
    

    希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 2022-06-15
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多