0

I was extending my magento sales order grid and I was having an error with it because of a conflict with the other extension on rewriting the grid.

0

Please follow this blog. It will help you to extend sales order grid using observer.

1) http://www.blog.magepsycho.com/extend-magento-sales-order-grid-using-event-observer/

2) https://www.magestyapps.com/blog/post/how-to-add-a-custom-column-to-order-grid-in-magento/

0
  1. Configure your extension to observe event 'core_layout_block_create_after'.

The best way to add a new column to the orders grid is to use event observers. In our case, we are going to use event 'core_layout_block_create_after'. To add an observer for this event we need to edit file /etc/config.xml of your custom module.

app/code/community/MyCompany/MyModule/etc/config.xml

<config>
...
<adminhtml>
    <events>
        <core_layout_block_create_after>
            <observers>
                <magestyapps_ordergrid_add_columns>
                    <class>MyCompany_MyModule_Model_Observer</class>
                    <method>addColumnsToGrid</method>
                </magestyapps_ordergrid_add_columns>
            </observers>
        </core_layout_block_create_after>
    </events>
</adminhtml>
...

2. Create an observer for the event

The next step is to create the observer class with the observing method in it:

app/code/community/MyCompany/MyModule/Model/Observer.php

<?php

 class MyCompany_MyModule_Model_Observer
{
/** 
 * Add new column to orders grid
 *
 * @param Varien_Event_Observer $observer
 * @return $this
 */
public function addColumnsToGrid(Varien_Event_Observer $observer)
{
    $block = $observer->getEvent()->getBlock();

    // Check whether the loaded block is the orders grid block
    if (!($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid)
        || $block->getNameInLayout() != 'sales_order.grid'
    ) {
        return $this;
    }

    // Add a new column rigth after the "Ship to Name" column
    $block->addColumnAfter('coupon_rule_name', [
        'header' => $block->__('Coupon Rule Name'),
        'index' => 'coupon_rule_name',
    ], 'shipping_name');

    return $this;
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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