I'm stuck at overriding a controller of a third party extension. I have followed the standard procedure for overriding a controller. I can't seem to get the route working.
I have done the following:
- Created my own Module
- Copied the path of the class I want to override
- Made a file in app/etc/modules - Module_Name.xml
- Made a config file in Module_Name/etc/ - config.xml
- Created the class and extended it with the class that I want to override
I think I've covered all the steps of overriding a controller.
Code part
In this part I will share all the file. I hope you guys can help me with this.
app/etc/modules/MDLOnline_PostNL.xml
<?xml version="1.0"?> <config> <modules> <MDLOnline_PostNL> <active>true</active> <codePool>local</codePool> </MDLOnline_PostNL> </modules> </config> MDLOnline/PostNL/etc/config.xml
<?xml version="1.0"?> <config> <modules> <MDLOnline_PostNL> <version>0.1.0</version> </MDLOnline_PostNL> </modules> <admin> <routers> <postnl> <args> <modules> <MDLOnline_PostNL before="TIG_PostNL">MDLOnline_PostNL</MDLOnline_PostNL> </modules> </args> </postnl> </routers> </admin> </config> Class override
MDLOnline/PostNL/controllers/PostnlAdminhtml/ShipmentController.php
<?php require_once 'TIG/PostNL/controllers/PostnlAdminhtml/ShipmentController.php'; class MDLOnline_PostNL_PostnlAdminhtml_ShipmentController extends TIG_PostNL_PostnlAdminhtml_ShipmentController { //override function public function massFullPostnlFlowAction($type = 'label') { die('custom controller'); } } Class that needs to be override
TIG/PostNL/controllers/PostnlAdminhtml/ShipmentController.php
<?php class TIG_PostNL_PostnlAdminhtml_ShipmentController extends TIG_PostNL_Controller_Adminhtml_Shipment { //This function is overriden public function massFullPostnlFlowAction($type = 'label') { /** @var TIG_PostNL_Helper_Carrier $helper */ $helper = Mage::helper('postnl/carrier'); $fullFlowAclResources = array( 'create_shipment', 'confirm', 'print_label', ); if (!$this->_checkIsAllowed($fullFlowAclResources)) { $helper->addSessionMessage( 'adminhtml/session', 'POSTNL-0155', 'error', $this->__('The current user is not allowed to perform this action.') ); $this->_redirect('adminhtml/sales_order/index'); return $this; } try { /** * Perform the full process for all selected orders. */ $this->_fullPostnlFlow($type); } catch (TIG_PostNL_Model_Core_Cif_Exception $e) { /** @var TIG_PostNL_Helper_Cif $cifHelper */ $cifHelper = Mage::helper('postnl/cif'); $cifHelper->parseCifException($e); $helper->logException($e); $helper->addExceptionSessionMessage('adminhtml/session', $e); $this->_redirect('adminhtml/sales_order/index'); return $this; } catch (TIG_PostNL_Exception $e) { $helper->logException($e); $helper->addExceptionSessionMessage('adminhtml/session', $e); $this->_redirect('adminhtml/sales_order/index'); return $this; } catch (Exception $e) { $helper->logException($e); $helper->addSessionMessage('adminhtml/session', 'POSTNL-0010', 'error', $this->__('An error occurred while processing this action.') ); $this->_redirect('adminhtml/sales_order/index'); return $this; } return $this; } } TIG/PostNL/etc/config.xml Admin Router
<admin> <routers> <adminhtml> <args> <modules> <postnl_admin after="Mage_Adminhtml">TIG_PostNL</postnl_admin> </modules> </args> </adminhtml> </routers> </admin>
TIG_PostNLmodule ?TIG_PostNL