1

My website uses version 1.7 and in fact I would like to add a column in the view of commandes.my config file:

<?xml version="1.0"?>
  <config>
   <modules>
      <Digitgold_AddColumnInfoPaiement>
         <version>1.0.0</version>
      </Digitgold_AddColumnInfoPaiement>
  </modules>
  <global>
    <blocks>
        <adminhtml>
            <rewrite>
                <sales_order_grid>Digitgold_AddColumnInfoPaiement_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
            </rewrite>
        </adminhtml>
    </blocks>
  </global>
</config>

and this is my class :

class Digitgold_AddColumnInfoPaiement_Adminhtml_Block_Sales_Order_Grid extends  Mage_Adminhtml_Block_Sales_Order_Grid
{

 public function __construct()
 {
    parent::__construct();
    $this->setId('sales_order_grid');
    $this->setUseAjax(true);
    $this->setDefaultSort('created_at');
    $this->setDefaultDir('DESC');
    $this->setSaveParametersInSession(true);
  }

protected function _prepareColumns()
 {
    $this->addColumn('payement', array(
        'header'=> Mage::helper('sales')->__('Mode de Paiement'),
        'width' => '120px',
        'index' => 'payement',
         ));
}
}

the problem is header appears only of the admin and below is all white.

4

Change <sales_order> to <sales_order_grid>

See How to extend Magento Order Grid?

E.g

<blocks>
   <adminhtml>
     <rewrite>
      <sales_order_grid>Inchoo_Test_Block_Adminhtml_Order_Grid</sales_order_grid>
     </rewrite>
   </adminhtml>
</blocks>

Please note: The above method is NOT the best option to accomplish this.

Method #2

Assuming that the field is added to sales_flat_order and sales_flat_order_grid db

In layout.xml (admin)

<?xml version="1.0"?>
<layout>
    <add_order_grid_column_handle>
        <reference name="sales_order.grid">
            <action method="addColumnAfter">
                <columnId>payement</columnId>
                <arguments module="sales" translate="header">
                    <header>Mode de Paiement</header>
                    <index>payement</index>
                    <type>text</type>
                    <width>110px</width>
                </arguments>
                <after>shipping_name</after>
            </action>
        </reference>
    </add_order_grid_column_handle>
    <adminhtml_sales_order_grid>
        <update handle="add_order_grid_column_handle" />
    </adminhtml_sales_order_grid>
    <adminhtml_sales_order_index>
        <update handle="add_order_grid_column_handle" />
    </adminhtml_sales_order_index>
<layout>
| improve this answer | |
  • Ok thank you for your help. For the first method, when i replace <sales_order> by <sales_order_grid> i get this error: Fatal error: Call to a member function setSaveParametersInSession() on a non-object. i don't understand why i have this error. i can't use the second method because the field is not added to sales_flat_order and sales_flat_order_grid db.i prefer, do not touch the defaut configuration – strauss Nov 6 '14 at 9:44
  • I just add up.. – strauss Nov 6 '14 at 11:15
  • <sales_order_grid>..._AddColumnInfoPaiement_Block_Adminhtml.. != class ..._AddColumnInfoPaiement_Adminhtml_Block_.. check your folder structure and rename your class or rewrite – Renon Stewart Nov 6 '14 at 11:26
  • i renamed the class and control folder structure but it still don't work – strauss Nov 6 '14 at 11:38
  • Please explain what "still don't work" mean? Also you need to copy the rest of the code to _prepareColumns() – Renon Stewart Nov 6 '14 at 11:42
1

Rewriting the Sales Order Grid is not the best solution as this is not needed because there is a Magento build-in solution that allows you to add extra columns. I made a complete example extension for this in add column to sales/orders grid

This extension adds a column to the sales_flat_order_grid table, populates the field for the current orders and an observer that will insert the data in the before save event every time an order is saved.

| improve this answer | |
  • A not to those who use this method - adding extra columns to the order grid table isn't a great way to go, the whole idea of this extra table is to maintain better performance for the grid. If you do have to add new columns be very sparing.... – Jonathan Hussey Nov 5 '14 at 19:27
  • Don't agree with you on that, its always better than creating joins or using the sales_flat_order table because of locking issues that can occur when creating or saving order data (with the change of loosing orders/order data). If the grid table isn't up-to-date thats no problem but you would not want to have that with your real order data. – Vladimir Kerkhoff Nov 5 '14 at 20:51
  • Fair enough. I don't actually feel there would be any locking issues as any locking will only be on a per row basis (being InnoDB) and orders are modified very little after creation. I have implemented a change to the orders grid with a join against the flat orders table on an install with 4 or 5 operators accessing the grid pretty constantly throughout the day and orders coming in around every 30 seconds and no reported issues. Needing to maintain custom duplicate data between the flat orders and grid table is also harder to maintain. – Jonathan Hussey Nov 6 '14 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.