0

I would like to add column to the backend order grid.

I then followed this tutorial : Tuto

on this model, I then tried to add a second column : the client company

I tried :

    <?php
class Mine_Ordergridmodule_Model_Observer
{

public function salesOrderGridCollectionLoadBefore($observer)
    {
        $collection = $observer->getOrderGridCollection();
        $select = $collection->getSelect();
        $select->joinLeft(array('payment'=>$collection->getTable('sales/order_payment')), 'payment.parent_id=main_table.entity_id',array('payment_method'=>'method'));

        //$select->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('company_name'=>'company'));
        $select->joinLeft(array('company'=>$collection->getTable('sales_flat_order_address')), 'company.parent_id=main_table.entity_id',array('company_name'=>'company'));


    }

}

and in my layout xml :

<layout>
    <sales_order_grid_update_handle>
        <reference name="sales_order.grid">
            <action method="addColumnAfter">
                <columnId>payment_method</columnId>
                <arguments>
                    <header>Payment Method</header>
                    <index>payment_method</index>
                    <filter_index>payment.method</filter_index>
                    <type>text</type>
                </arguments>
                <after>grand_total</after>
            </action>
            <action method="addColumnAfter">
                <columnId>company</columnId>
                <arguments>
                    <header>Company</header>
                    <index>company</index>
                    <type>text</type>
                </arguments>
                <after>shipping_name</after>
            </action>
        </reference>
    </sales_order_grid_update_handle>
    <adminhtml_sales_order_grid>
        <!-- apply layout handle defined above -->
        <update handle="sales_order_grid_update_handle" />
    </adminhtml_sales_order_grid>
    <adminhtml_sales_order_index>
        <!-- apply layout handle defined above -->
        <update handle="sales_order_grid_update_handle" />
    </adminhtml_sales_order_index>
</layout>

but it is not working...

2

1 Answer 1

0

I found the solution Here : link

which gives :

<?php
class Mine_Ordergridmodule_Model_Observer
{

public function salesOrderGridCollectionLoadBefore($observer)
    {
        $collection = $observer->getOrderGridCollection();
        $select = $collection->getSelect();
        $select->joinLeft(array('payment'=>$collection->getTable('sales/order_payment')), 'payment.parent_id=main_table.entity_id',array('payment_method'=>'method'));

        $select->join(
                array('address' => $collection->getTable("sales/order_address")),
                'main_table.entity_id = address.parent_id AND address.address_type = "billing"',
                array('company')
            );
    }

}

The added Helper function :

<?php
class Mine_Ordergridmodule_Helper_Data extends Mage_Core_Helper_Abstract
{

 public function getCompanyColumnParams()
    {
        return array(
            'header' => 'Company',
            'index' => 'company',
            'type' => 'text',               
        );
    } 
}

the XML

<layout>
    <sales_order_grid_update_handle>
        <reference name="sales_order.grid">
            <action method="addColumnAfter">
                <columnId>payment_method</columnId>
                <arguments>
                    <header>Payment Method</header>
                    <index>payment_method</index>
                    <filter_index>payment.method</filter_index>
                    <type>text</type>
                </arguments>
                <after>grand_total</after>
            </action>
            <action method="addColumnAfter">
                <columnId>company</columnId>
                <arguments helper="mine_ordergridmodule/getCompanyColumnParams" />
                <after>shipping_name</after>
            </action>
        </reference>
    </sales_order_grid_update_handle>
    <adminhtml_sales_order_grid>
        <!-- apply layout handle defined above -->
        <update handle="sales_order_grid_update_handle" />
    </adminhtml_sales_order_grid>
    <adminhtml_sales_order_index>
        <!-- apply layout handle defined above -->
        <update handle="sales_order_grid_update_handle" />
    </adminhtml_sales_order_index>
</layout>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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