views:

183

answers:

1

I want an additional column in the Order(s) Grid for Admin. Assuming its Customer Group Id.

My app/etc/modules/MyProject_Adminhtml looks like:

<?xml version="1.0"?>

<config>
    <modules>
        <MyProject_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </MyProject_Adminhtml>
    </modules>
</config>

My app/code/local/MyProject/Adminhtml/etc/config.xml looks like:

<?xml version="1.0"?>
<config>
    <modules>
        <MyProject_Adminhtml>
            <version>1.0.0</version>
        </MyProject_Adminhtml>    
    </modules>

    <global>
          <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>MyProject_Adminhtml_Block_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>

      </global>

  </config>

And in app/code/local/MyProject/Adminhtml/Block/Sales/Order/Grid.php I have overridden Mage_Adminhtml_Block_Sales_Order_Grid

class MyProject_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{

    protected function _prepareColumns()
    {
        .... unchanged code from Mage_Adminhtml_Block_Sales_Order_Grid::_prepareColumns ...

        $this->addColumn('customer_group_id', array(
            'header' => Mage::helper('sales')->__('Customer Group Id'),
            'index' => 'customer_group_id',
            'type'  => 'text',
        ));

         .... unchanged code from Mage_Adminhtml_Block_Sales_Order_Grid::_prepareColumns ...
    }
}

Is there something I am missing because I don't see anything in Order Grid. I am using Magento 1.4.1.1

On Anda B's comment I wrote the following line:

var_dump($this->getLayout()->createBlock('MyProject_Adminhtml_Block_Sales_Order_Grid'));

in app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php

Then, I selected 'Create New Order' and Cancel the order to see the result of execution of var_dump, and I see the following:

/var/www/magento/var/report/72990635: line 10: syntax error near unexpected token `}' /var/www/magento/var/report/72990635: line 10: `#9 {main}";s:3:"url";s:80:"/index.php/admin/sales_order_create/cancel/key/0624033594dd63d9e145fc538f4c6bbb/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}'
+1  A: 

In modules/etc you have Atzen_Adminhtml but your project is MyProject_Adminhtml. Except this problem the code should work: even if you don't have the customer_group_id in sales table, the new column should appear in the grid.

Anda B
Actually its the actual filename/namespace. I replaced Atzen every where while posting it on SO. So, consider that this as a typo in the question only.
Ozair Kafray
Ok, check then if magento can find your block: try to add in a controller var_dump($this->getLayout()->createBlock('MyProject_Adminhtml_Block_Sales_Order_Grid'))
Anda B
I tried doing this in app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.phpSo, when I cancel an order, I see the following:/var/www/magento/var/report/72990635: line 10: syntax error near unexpected token `}'/var/www/magento/var/report/72990635: line 10: `#9 {main}";s:3:"url";s:80:"/index.php/admin/sales_order_create/cancel/key/0624033594dd63d9e145fc538f4c6bbb/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}'
Ozair Kafray
Add this in Mage_Adminhtml_Sales_OrderController protected function _initAction() { var_dump($this->getLayout()->createBlock('MyProject_Adminhtml_Block_Sales_Order_Grid')); // the rest of the code } and go to the orders grid, if the result is false it means magento can't find your module
Anda B
I see a lot of text output before the grid, and it starts with: object(MyProject_Adminhtml_Block_Sales_Order_Grid)#281I think it means that Magento does find the class. The object dump starts with:{ ["_columns":protected]=> array(0) { } ["_lastColumnId":protected]=> NULL ["_collection":protected]=> NULL ["_varNameLimit":protected]=> string(5) "limit" ["_varNamePage":protected]=> string(4) "page" ["_varNameSort":protected]=> string(4) "sort" ["_varNameDir":protected]=> string(3) "dir" ["_varNameFilter":protected]=> string(6)
Ozair Kafray
Ok, I've created the same module as you did and it works, maybe you have another module installed that overrides the Mage_Adminhtml_Block_Sales_Order_Grid? to check this you could add var_dump($this->getLayout()->createBlock('adminhtml/sales_order_grid')); in the same location as the previous code, it should start with object(MyProject_Adminhtml_Block_Sales_Order_Grid) if magento uses your module to override the original block, with Mage_Adminhtml_Block_Sales_Order_Grid if it doesn't, if it's something else it means you have another module installed that overrides the same block as you did.
Anda B
Thanks, Anda. It works now. It did display the right object. I think it takes some time to show. I just deployed these files to the production server now, and it doesn't show there yet. I hope it will appear there in a little while as well.
Ozair Kafray
Try to refresh the cache.
Anda B
Ok, its there now. Now about getting the data there. Is it _prepareCollection that I have to override for that?
Ozair Kafray