2

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> 
4
  • 1
    Could you share the admin router config part of the TIG_PostNL module ? Commented Mar 9, 2018 at 17:57
  • Can you add please the exact path's of your files and the config.xml of TIG_PostNL Commented Mar 9, 2018 at 21:33
  • Should I add the whole config.xml of TIG? It's a long document. Commented Mar 12, 2018 at 16:34
  • Try my answer please Commented Mar 12, 2018 at 16:49

1 Answer 1

2
  1. app/etc/modules/MDLOnline_PostNL.xml and not app/etc/MDLOnline_PostNL.xml

  2. MDLOnline/PostNL/etc/config.xml

<config> <modules> <MDLOnline_PostNL> <version>0.1.0</version> </MDLOnline_PostNL> </modules> <admin> <routers> <adminhtml> // not <postnl> <args> <modules> <MDLOnline_PostNL before="TIG_PostNL">MDLOnline_PostNL</MDLOnline_PostNL> </modules> </args> </adminhtml> </routers> </admin> </config> 
  1. don't forget to clean the cache.
1
  • With pleasure, good luck ! Commented Mar 13, 2018 at 8:33

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.