1

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!

2

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.

  • It seems i'm making something wrong, here is my config.xml after your answer: pastebin.com/caz87NMq and here is my /app/code/loca/VivasIndustries/MassCustomStatusses/controllers/IndexController.php: pastebin.com/89Q9dfQT And again when i try to update i got error 404 on mymagento.com/index.php/masscustomstatusses/controller/action/… – Venelin Vasilev Nov 28 '14 at 22:44
  • The admin/routers setup should not be in the global node. Move it up a level, as a child of the root config node. – Rick Buczynski Nov 29 '14 at 1:34
  • Now i got 404 but in the admin panel.. – Venelin Vasilev Nov 29 '14 at 14:36
  • Please check the path to your controller, should be something like app/code/local/VivasIndustries/MassCustomStatusses/controllers/ControllerController.php -- note the lowercase c in the controllers directory. – Rick Buczynski Dec 2 '14 at 14:17
  • Now i got 404 page redirect.any solution? – meet Dec 11 '17 at 6:42

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.