skip to Main Content

I want to override sales order grid in Magento admin. I have created custom module for that, but seems my override doesn’t work. There is no errors.

Please find my codes above:

app/etc/modules/

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

app/code/local/Bikebear/SalesGrid/etc

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

What I’m doing wrong and why there is no result? Thanks in advance.

3

Answers


  1. Chosen as BEST ANSWER

    Thanks guys for the help, i have resolved the issue.

    Issue was some another module was calling there, so i have change that on that module.

    Thanks


  2. You can replace _prepareCollection() function with following code in app/code/local/Bikebear/SalesGrid/Block/Adminhtml/Sales/Order

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

    Or Else you can try with this following code

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

    Hope it will help.

    Login or Signup to reply.
  3. You can add this in _prepareCollection function

    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
    

    so code should be like this as per your function

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

    Hope it will help you 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search