Magento – Add new mass action in order grid in magento 1.9

magento-1.9massactionpacking-slippdf

enter image description hereI am using Magento 1.9.1 .

I will create new mass action same like Print Packingslips in order grid also download pdf for same as Print Packingslips but some customization in pdf as per requirement.any one create any module or else knowing step so please share.

Best Answer

Flow below steps

Step:1

Create file Ar_Custom.xml at location app\etc\modules and add below code

<?xml version="1.0"?>
<config>
    <modules>
        <Ar_Custom>
            <active>true</active>
            <codePool>community</codePool>
        </Ar_Custom>
    </modules>
</config>

Step:2 Create Observer.php at location app\code\community\Ar\Custom\Model\

<?php
class Ar_Custom_Model_Observer
{
    public function addMassAction($observer)
    {
        $block = $observer->getEvent()->getBlock();
        $this->_block = $block;
        if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'sales_order') {
            $block->addItem('custom_action', array(
                'label' => Mage::helper('sales')->__('Custom Action'),
                'url' => $block->getUrl('*/custom/masscustom'),
            ));
        }
    }
}

Step:3 Create CustomController.php file at location app\code\community\Ar\Custom\controllers\Adminhtml\CustomController.php and below code

<?php
class Ar_Custom_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{

    public function massCustomAction()
    {
        $orderIds = $this->getRequest()->getPost('order_ids', array());
        $this->_redirect('adminhtml/sales_order/');
    }
}

Step:4 Create config.xml file at location app\code\community\Ar\Custom\etc and add below code

<?xml version="1.0"?>
<config>
    <modules>
        <Ar_Custom>
            <version>1.0.1</version>
        </Ar_Custom>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Ar_Custom after="Mage_Adminhtml">Ar_Custom_Adminhtml</Ar_Custom>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
     <adminhtml>
        <events>
            <core_block_abstract_prepare_layout_before>
                <observers>
                    <newmodule_core_block_abstract_prepare_layout_before>
                        <type>model</type>
                        <class>Ar_Custom_Model_Observer</class>
                        <method>addMassAction</method>
                    </newmodule_core_block_abstract_prepare_layout_before>
                </observers>
            </core_block_abstract_prepare_layout_before>
        </events>
    </adminhtml>
    <global>
        <models>
            <custom>
                    <class>Ar_Custom_Model</class>
            </custom>
        </models>
        <resources>
            <custom_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </custom_write>
            <custom_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </custom_read>
        </resources>
    </global>
</config>

Step:5 Flush and refresh all cache in admin end.