1

I want to add a checkbox on admin grid in sales order page. I want to have in between "New order Rss" and "export menu".

Having a hard time figuring out how to do this as I am quite new to Magento.

Here is what I have done up to now:

I created a module and from what I have read, I should avoid doing rewrites. So I am trying to work it out with observers.

Here is the config of my module:

<config>
    <adminhtml>
        <events>
            <core_block_abstract_prepare_layout_before>
                <observers>
                    <training_testing>
                        <type>model</type>
                        <class>Training_Testing_Model_Observer</class>
                        <method>coreBlockAbstractPrepareLayoutBefore</method>
                    </training_testing>
                </observers>
            </core_block_abstract_prepare_layout_before>
        </events>
    </adminhtml>
</config>

Here is my observer:

class Training_Testing_Model_Observer {

    public function coreBlockAbstractPrepareLayoutBefore(Varien_Event_Observer $event){

        $block = $event->getBlock();
        if(!isset($block)){
            return $this;
        }

        if($block->getType() =='adminhtml/sales_order_grid'){

            // should i set a new admin grid template here??

        }



    }

} 

I am having a hard time trying to figure what should be my next step. Should I set a new template where I check if its the sales order grid block?

Added a link to show exactly where I want to have the checkbox.

1

If you want to switch out the template I wouldn't use an observer but the layout xml. Alltough I wonder what the checkbox is for. The fact that you have massactions and a mass select link should be enough no?

If you still want to add the checkbox on a custom environment, I suggest you override the app/design/adminhtml/default/default/template/widget/grid.phtml template.

and add your checkbox manually, if its for a Magento extension, I would advise you to think twice and maybe make a massaction button trough an observer like this:

<events>
    <core_block_abstract_prepare_layout_before>
        <observers>
            <myextension_core_block_abstract_prepare_layout_before>
                 <class>modeldeclaration/observer</class>
                 <method>block_abstract_prepare_layout_before</method>
            </myextension_core_block_abstract_prepare_layout_before>
        </observers>
    </core_block_abstract_prepare_layout_before>
 </events>

In your observer add:

public function block_abstract_prepare_layout_before($observer) {
        $block = $observer->getEvent()->getBlock();
        if($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction && $block->getRequest()->getControllerName() == 'sales_order')
        {
            $block->addItem('my_action', array(
                'label' => 'My Action',
                'url' => Mage::helper("adminhtml")->getUrl('index'),
            ));
        }
} 

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.