Add Mass Action to Sales > Orders Grid in Magento
Hello! I hope this detailed guide helps you solve your issue of adding a mass action button for printing RMA forms on the Sales > Orders grid in your Magento store.
Understanding Your Current Setup
You’ve already done some great work by using the Admin Order Printing extension and customizing the form layout. However, you’re facing two main challenges:
- You want to add a Mass Action option so you can print multiple RMAs at once instead of opening each order.
- Currently, your added option appears at the top of the list, but you want it sorted to the bottom.
Let’s tackle these issues step-by-step using the second method described in the MagePsycho tutorial.
Adding a Mass Action with Events
Step 1: Add Event Observer to config.xml
Open your config.xml file and add the following code inside the <global> tag:
<events>
<adminhtml_sales_order_grid_collection_load_before>
<observers>
<sales_order_grid_collection_customization>
<class>YourCompany_YourModule_Model_Observer</class>
<method>addMassAction</method>
</sales_order_grid_collection_customization>
</observers>
</adminhtml_sales_order_grid_collection_load_before>
</events>
Replace YourCompany_YourModule with your actual company and module names.
Step 2: Create the Observer File
Create a file named Observer.php inside your module’s observer folder (usually located at app/code/local/YourCompany/YourModule/Model/Observer).
Add the following code to this file:
<?php
class YourCompany_YourModule_Model_Observer {
public function addMassAction($observer) {
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
$massactionBlock = $block->getChild('grid_massaction');
$url = Mage::helper('adminhtml')->getUrl('yourmodule/yourcontroller/massPrintAction');
$massactionBlock->addItem(
'rma_print',
array(
'label' => 'Print RMA',
'url' => $url
)
);
}
}
}
Replace yourmodule and yourcontroller with the actual module and controller names where you’ll handle the mass print action.
Sorting Your Added Option to the Bottom
To sort your added option to appear at the bottom of the list, you need to modify the Mage_Adminhtml_Block_Sales_Order_Grid_Massaction block. Unfortunately, this requires a rewrite of the core file.
Step 3: Rewrite and Modify the Mass Action Block
In your module’s config.xml, add the following rewrite:
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid_massaction>
YourCompany_YourModule_Block_Sales_Order_Grid_Massaction
</sales_order_grid_massaction>
</rewrite>
</adminhtml>
</blocks>
</global>
Then, create a file named Sales_Order_Grid_Massaction.php in your module’s block folder:
<?php
class YourCompany_YourModule_Block_Sales_Order_Grid_Massaction extends Mage_Adminhtml_Block_Sales_Order_Grid_Massaction {
protected function _prepareMassaction()
{
$this->_setData('action', array(
'rma_print' => array(
'label' => $this->helper('adminhtml')->__('Print RMA'),
'url' => Mage::helper('adminhtml')->getUrl('yourmodule/yourcontroller/massPrintAction')
)
));
return parent::_prepareMassaction();
}
}
Again, replace yourmodule and yourcontroller with your actual module and controller names.
Conclusion
By following these steps, you should now have successfully added a mass action button for printing RMAs to the bottom of the Sales > Orders grid in your Magento store. This will greatly improve the efficiency of your RMA process.
Remember to refresh the cache after making these changes.
If you still encounter any issues or need further assistance with custom Magento development, feel free to explore our Magento services at Laravel Company for expert help and solutions tailored to your business needs.