magentomagento-1.9magento-1.9.1

show attribute value in admin magento


I am new in magento.

I added an extra field in sales_flat_order table i.e.,order_campaign_params When a customer completed its order, data is inserting into this table. Now i want to show this attribute value in admin. I added an extra column in admin i.e., Order Utm Source but data is not showing. Please tell me how to show the attribute value in admin. Please see the code for adding column

 $this->addColumn('order_campaign_params', array(
           'header' => Mage::helper('orderreport')->__('Order Utm Source'),
           'index' => 'order_campaign_params',
           'filter_index'=>'customer_entity.order_campaign_params',
           'width' => '70px',
       ));

But how to show data of that field, Please explain.

Please see the structure:

customer_entity_varchar table

value_id entity_type_id  attribute_id  entity_id    value 
 136977             1          5        43120     Sanghamitra
 136978             1          7        43120     samal
 136979             1          12       43120     0860142023b7a810ce66a21b68
 136980             1          174      43120     data(order_compaign_params)
 136981             1          3        43120     Kalazone.in

Thanks


Solution

  • Sales order grid is build from sales_flat_order_grid table. The column order_campaign_params exists in sales_flat_order table and not sales_flat_order_grid table.

    So you need to MySQL join with sales_flat_order_grid table sales_flat_order table like below:

    $select = $collection->getSelect();
    $select->joinLeft(array('order' => Mage::getModel('core/resource')->getTableName('sales/order')), 'order.entity_id=main_table.entity_id',
    array('order_campaign_params' => 'order_campaign_params'));
    $select->joinLeft(array('custeav' => 'customer_entity_varchar'), 'custeav.attribute_id=main_table.order_campaign_params', array('*'));
    

    The order_campaign_params column will now be displayed in the grid.

    Hope this helps.