1
votes

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
First of all, what is purpose of overriding this grid? What you want to do with it? Do you want just hide few columns like in your sample? Overrides is not a good practice in Magento and in most cases you can use Observers. Please advice with idea what you want to do and I can try to help you. Thanks.mrDinkelman
Actually i want to hide "base_grand_total" and "billing_name" and i want to add new column for "shipping address" and "Delivery date". please help me for this, Plz let me know how can i achieve this. thanksAmrish

3 Answers

0
votes

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.

0
votes

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

0
votes

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 :)