Monday, February 25, 2013

MAgento : Add custom action to Sales Order Grid

Here we use an event core_block_abstract_prepare_layout_before
1. Add following script in config.xml
<events>
<core_block_abstract_prepare_layout_before>
        <observers>
                <bdaction_block_abstract_prepare_layout_before>
                        <type>singleton</type>
                        <class>Bd_Test_Model_Observer</class>
                        <method>addMassCustomAction</method>
                </bdaction_block_abstract_prepare_layout_before>
        </observers>
</core_block_abstract_prepare_layout_before>
</events>
2.Create a observer class like Bd_Test_Model_Observer
then add a method
public static function addMassCustomAction($observer)
{
    $block = $observer->getEvent()->getBlock();
    if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
        && $block->getRequest()->getControllerName() == 'sales_order')
    {
        $block->addItem('customaction', array(
        'label' => 'Custom Action',
        'url' => Mage::helper('adminhtml')->getUrl('module/controller/action'),
        ));
    }
}
3.At last create that controller and action method

1 comment: