How can i get the selected order ids in custom act

2019-06-11 08:19发布

问题:

I have added new mass action named as invoice in sales order. and I want to create an invoice on clicking this action. how I get the order id when I select the order from list and than select invoice in the action on sales order. my new mass action invoice are shown in the action but when I select the invoice action and submit than I am not able to make the invoice for the selected order. my code is:-

app/code/local/MagePsycho/Newmodule/Block/Sales/Order/Grid.php

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

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

app/code/local/MagePsycho/Newmodule/etc :-

 <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>MagePsycho_Newmodule_Block_Sales_Order_Grid</sales_order_grid>
                </rewrite>

<events>
        <core_block_abstract_prepare_layout_before>
            <observers>
                <newmodule_core_block_abstract_prepare_layout_before>
                    <class>newmodule/observer</class>
                    <method>addMassAction</method>
                </newmodule_core_block_abstract_prepare_layout_before>
            </observers>
        </core_block_abstract_prepare_layout_before>
    </events>
            </adminhtml>
        </blocks> 
    </global>

app/code/local/MagePsycho/Newmodule/Model/Observer.php :-

<?php
class MagePsycho_Newmodule_Model_Observer
{
    public function addMassAction($observer)
    {
        echo 'hello magento';
        $block = $observer->getEvent()->getBlock();
        if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
            && $block->getRequest()->getControllerName() == 'sales_order')
        {
            $block->addItem('newmodule', array(
                'label' => 'New Mass Action Title',
                'url' => Mage::app()->getStore()->getUrl('newmodule/controller/action'),
            ));
        }
    }
}

Please suggest, what can I do to make invoice on my action .

回答1:

You can get this by getRequest in getParam method of your custom controllers action like below

  public function massChangeTypeAction()
    {
      $orderIds = (array)$this->getRequest()->getParam('order_ids');        
    }

you can print this $orderIds to get selected order from grid

hope this will sure work for you.