问题
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 then 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.
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'),
));
}
}
}
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 $orderIds
to get selected order from grid.
来源:https://stackoverflow.com/questions/24884544/how-can-i-get-the-selected-order-ids-in-custom-action-in-sales-order-onclick