I want to create new mass action inside Order grid which will create new Shipment but I have problem with my action. When I click submit button my action don't work but only redirect me on homepage.
My app/code/local/CFO/ShipAction/etc/config.xml
<config>
<modules>
<CFO_ShipAction>
<version>0.1.0</version>
</CFO_ShipAction>
</modules>
<admin>
<routers>
<cfoshipaction>
<use>admin</use>
<args>
<module>CFO_ShipAction_Adminhtml</module>
<frontName>cfoshipaction</frontName>
</args>
</cfoshipaction>
</routers>
</admin>
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<CFO_ShipAction_Model_Observer>
<type>singleton</type>
<class>CFO_ShipAction_Model_Observer</class>
<method>addShipAction</method>
</CFO_ShipAction_Model_Observer>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
</config>
My app/code/local/CFO/ShipAction/Model/Observer.php
class CFO_ShipAction_Model_Observer
{
public function addShipAction($observer){
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
&& $block->getRequest()->getControllerName() == 'sales_order')
{
$block->addItem('cfoshipaction', array(
'label' => 'Create shipment',
'url' => Mage::app()->getStore()->getUrl('cfoshipaction/adminhtml_massactions/createShipment')
));
}
}
}
And app/code/local/CFO/ShipAction/controllers/Adminhtml/MassActionsController.php
require_once 'Mage/Adminhtml/controllers/Action.php';
class CFO_ShipAction_Adminhtml_MassActionsController extends Mage_Adminhtml_Controller_Action {
public function createShipmentAction() {
$orderIds = $this->getRequest()->getPost('order_ids', array());
foreach ($orderIds as $orderId){
try {
$order = Mage::getModel('sales/order')->load($orderId);
if($order->canShip()) {
//Create shipment
$shipmentid = Mage::getModel('sales/order_shipment_api')
->create($order->getIncrementId(), array());
//Add tracking information
$ship = Mage::getModel('sales/order_shipment_api')
->addTrack($order->getIncrementId(), array());
}
}catch (Mage_Core_Exception $e) {
print_r($e);
}
}
$this->_redirect('adminhtml/sales_order/');
}
}
I'm know that problem is with my router, but I don't know where. I tried 2 options for initializing my router but both not help. Can anybody see what's missing? Thanks!
EDIT:
There is my other config.xml
with other router which I've tried to use but sill noting:
<config>
...
<admin>
<routers>
<adminhtml>
<args>
<CFO_ShipAction before="Mage_Adminhtml">CFO_ShipAction_Adminhtml</CFO_ShipAction>
</args>
</adminhtml>
</routers>
</admin>
...
</config>
Thanks for help !
mywebsite.com/index.php/cfoshipaction/adminhtml_massactions/createShipment/