Magento – Adding new custom mass order status action

gridmassactionorder-grid

I am using Magento 1.9.1 .

I am working on a new extension which is adding new custom mass status action here:

enter image description here

Here is my code:

/app/code/local/VivasIndustries/MassCustomStatusses/etc/config.xml :

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_MassCustomStatusses>
      <version>0.1.0</version>
    </VivasIndustries_MassCustomStatusses>
  </modules>
<global>
  <adminhtml>
    <events>
        <core_block_abstract_prepare_layout_before>
            <observers>
                <masscustomstatusses_core_block_abstract_prepare_layout_before>
                    <class>masscustomstatusses/observer</class>
                    <method>newMassAction1</method>
                </masscustomstatusses_core_block_abstract_prepare_layout_before>
            </observers>
        </core_block_abstract_prepare_layout_before>
    </events>
</adminhtml>
    <blocks>
        <adminhtml>
            <rewrite>
                <sales_order_grid>VivasIndustries_MassCustomStatusses_Block_Sales_Order_Grid</sales_order_grid>
            </rewrite>
        </adminhtml>
    </blocks> 
</global>
</config>

/app/code/local/VivasIndustries/MassCustomStatusses/Block/Sales/Order/Grid.php:

<?php
class VivasIndustries_MassCustomStatusses_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{   
    protected function _prepareMassaction()
    {
        parent::_prepareMassaction();

        // Append new mass action option 
        $this->getMassactionBlock()->addItem(
            'masscustomstatusses',
            array('label' => $this->__('New Mass 1'), 
                  'url'   => $this->getUrl('masscustomstatusses/controller/action') //this should be the url where there will be mass operation
            )
        );
    }
}

/app/code/local/VivasIndustries/MassCustomStatusses/Model/Observer.php:

<?php
class VivasIndustries_MassCustomStatusses_Model_Observer
{
    public function newMassAction1($observer)
    {
        $block = $observer->getEvent()->getBlock();
        if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
            && $block->getRequest()->getControllerName() == 'sales_order')
        {
            $block->addItem('masscustomstatusses', array(
                'label' => 'New Mass 1',
                'url' => Mage::app()->getStore()->getUrl('masscustomstatusses/controller/action'),
            ));
        }
    }
}

So here is what i've done by this guide: http://www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/

The actions is appearing but when i select it and try to update the order statuss i get error for not exising link like this: http://mymagento.com/index.php/masscustomstatusses/controller/action/key/59418867a73fa5784acb31a23b2a1510/

I know i must add some more things but i have no idea what i should add.

Can you help me out so i can make this thing update the status ?

Thanks in advance!

Best Answer

You've done what you need to up to wiring in your controller.

First you need to declare a route for your controller(s) in the module config XML:

...
<admin>
    ...
    <routers>
        <masscustomstatusses>
            <use>admin</use>
            <args>
                <module>VivasIndustries_MassCustomStatusses</module>
                <frontName>masscustomstatusses</frontName>
            </args>
        </masscustomstatusses>
    </routers>
    ...
</admin>
...

Then build the controller:

<?php

class VivasIndustries_MassCustomStatusses_ControllerController
    extends Mage_Adminhtml_Controller_Action
{

    public function actionAction()
    {
        // Update status here
        // Can fetch selected items with $this->getRequest()->getParam()

        die('Looks like it works');
    }

}

I've used your naming convention exactly as you have described, though I doubt that's what you really want. Better to use standard Magento convention, with controller named IndexController and base action named indexAction. But you should get the idea.


Clear cache and try to run that mass action. The die statement should run, and fill in the blanks from there.

NOTE: I should point out that you're doing the same thing twice. You are both extending the sales order grid to add a mass action AND injecting it via event observer. As the article you reference points out, those are 2 different ways to do the same thing. You should choose one of those methods, only.

Related Topic