I would like to override the core Controller.
Path: app\code\core\Mage\Adminhtml\controllers\Sales\OrderController.php
And then, I create the custom extension for overriding this controller.
Here is my file structure:
config: app\code\local\Mypackage\MyModule\etc\config.xml
<?xml version="1.0"?>
<config>
 <modules>
 <Mypackage_MyModule>
 <version>0.1.0</version>
 </Mypackage_MyModule>
 </modules>
 <admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <Mypackage_MyModule before="Mage_Adminhtml">Mypackage_MyModule</Mypackage_MyModule>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
</config>
controllers: app\code\local\Mypackage\MyModule\controllers\Sales\OrderController.php
<?php
require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'Sales_OrderController.php';
class Mypackage_MyModule_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
 /**
 * View order detale
 */
 public function viewAction()
 {
 $this->_title($this->__('Sales'))->_title($this->__('Orders'));
 //etc...
 }
}
However, it don't work.
Any suggestion for me? Please help. Thank you.
EDIT:
I am using EE 1.14
EDIT2:
I had modified these file:
config.xml:
<?xml version="1.0"?>
<config>
 <modules>
 <Mypackage_MyModule>
 <version>0.1.0</version>
 </Mypackage_MyModule>
 </modules>
 <admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <Mypackage_MyModule before="Mage_Adminhtml">Mypackage_MyModule_Adminhtml</Mypackage_MyModule>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
</config>
app\code\local\Mypackage\MyModule\controllers\Adminhtml\Sales\OrderController.php:
<?php
require_once(Mage::getModuleDir('controllers','Mage_Adminhtml').DS.'Sales' . DS . 'OrderController.php');
class Mypackage_MyModule_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
 /**
 * View order detale
 */
 public function viewAction()
 {
 die(":D"); //for test
 }
}
But still don't work:(
Modules : app/etc/modules/Mypackage_MyModule.xml
<?xml version="1.0"?>
<config>
 <modules>
 <Mypackage_MyModule>
 <active>true</active>
 <codePool>local</codePool>
 </Mypackage_MyModule>
 </modules>
</config>
EDIT3:
I had found the issue. The problem had written on below reply message.
- 
 do you have create Mypackage_MyModule.xml?Amit Bera– Amit Bera ♦2016年07月27日 06:35:41 +00:00Commented Jul 27, 2016 at 6:35
 - 
 yes. I had done it.Yoshino– Yoshino2016年07月27日 06:58:39 +00:00Commented Jul 27, 2016 at 6:58
 - 
 It still using the core Controller: app\code\core\Mage\Adminhtml\controllers\Sales\OrderController.php. look like not working.Yoshino– Yoshino2016年07月27日 07:06:29 +00:00Commented Jul 27, 2016 at 7:06
 
5 Answers 5
You included OrderController.php wrongly. It should be like this :
require_once(Mage::getModuleDir('controllers','Mage_Adminhtml').DS.'Sales' . DS . 'OrderController.php');
Ensure your development mode is ON and cache is removed. This will definitely point out the error in your codes.
Also it is better to move your controllers in a directory called Adminhtml. So that you can uniquely distinguish both frontend controller and admin controllers. In order to do this, you need to do this.
File : config.xml
<config>
 <admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <Mypackage_MyModule before="Mage_Adminhtml">Mypackage_MyModule_Adminhtml</Mypackage_MyModule>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
</config>
File : app\code\local\Mypackage\MyModule\controllers\Adminhtml\Sales\OrderController.php
<?php
require_once(Mage::getModuleDir('controllers','Mage_Adminhtml').DS.'Sales' . DS . 'OrderController.php');
class Mypackage_MyModule_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
 /**
 * View order detale
 */
 public function viewAction()
 {
 $this->_title($this->__('Sales'))->_title($this->__('Orders'));
 //etc...
 }
}
 - 
 thanks for your answer. I had already turn on the development mode but can't see any error...Yoshino– Yoshino2016年07月27日 06:52:28 +00:00Commented Jul 27, 2016 at 6:52
 - 
 error comes in log files which you can find in
var\logdirectory.Rajeev K Tomy– Rajeev K Tomy2016年07月27日 06:53:44 +00:00Commented Jul 27, 2016 at 6:53 - 
 @Mokona you have your module activation file at
app/etc/modules?Rajeev K Tomy– Rajeev K Tomy2016年07月27日 06:58:57 +00:00Commented Jul 27, 2016 at 6:58 - 
 yeah. i had done it but still don't workYoshino– Yoshino2016年07月27日 07:01:16 +00:00Commented Jul 27, 2016 at 7:01
 
I have already find out the answer.
As I am using EE 1.14, therefore, my Magento system have another Core programm called "Enterprise".
And, I find out Enterprise_SalesArchive this module had already overrided the app\code\core\Mage\Adminhtml\controllers\Sales\OrderController.php once.
app\code\core\Enterprise\SalesArchive\etc\config.xml:
<admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <enterprise_salesarchive before="Mage_Adminhtml">Enterprise_SalesArchive_Adminhtml</enterprise_salesarchive>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
Therefore, Here is my answer.
config.xml:
<config>
 <modules>
 <Mypackage_MyModule>
 <version>0.1.0</version>
 </Mypackage_MyModule>
 </modules>
 <admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <Mypackage_MyModule before="Enterprise_Salesarchive">Mypackage_MyModule_Adminhtml</Mypackage_MyModule>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
</config>
app\code\local\Mypackage\MyModule\controllers\Adminhtml\Sales\OrderController.php:
<?php
require_once 'Enterprise/SalesArchive/controllers/Adminhtml/Sales/OrderController.php';
class Mypackage_MyModule_Adminhtml_Sales_OrderController extends Enterprise_SalesArchive_Adminhtml_Sales_OrderController
{
 /**
 * View order detale
 */
 public function viewAction()
 {
 die(":DD"); //for test
 }
}
Thanks for you all help.
Admin configuration should be content Adminhtml in xml tag so your configuration in config.xml will be like below
 <!--Admin Configuration -->
 <admin>
 <routers>
 <adminhtml>
 <args>
 <modules>
 <Mypackage_MyModule before="Mage_Adminhtml">Mypackage_MyModule_Adminhtml</Mypackage_MyModule>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
And your controller file should be like
require_once(Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS."Sales".DS."OrderController.php");
class Mypackage_MyModule_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController {
 /**
 * View order detail
 */
 public function viewAction()
 {
 $this->_title($this->__('Sales'))->_title($this->__('Orders'));
 //etc...
 }
}
hope it will work from your end.
 - 
 It will work without
Adminhtml. But it is the best practice to keepAdmnhtmlalways.Rajeev K Tomy– Rajeev K Tomy2016年07月27日 06:51:05 +00:00Commented Jul 27, 2016 at 6:51 - 
 yes it should be good practice to follow, so someone another programmer can easily workliyakat– liyakat2016年07月27日 06:58:55 +00:00Commented Jul 27, 2016 at 6:58
 - 
 thanks for answer. I had modified these files but still don't work:(Yoshino– Yoshino2016年07月27日 07:02:16 +00:00Commented Jul 27, 2016 at 7:02
 - 
 did you clear cache ? or look for any log in log files ? as per above file it should work for sales order detailliyakat– liyakat2016年07月27日 07:05:54 +00:00Commented Jul 27, 2016 at 7:05
 - 
 yeah. I had check it but there is no any error log about this controller in system.log(var/log). and, I had disable the cache function....:(Yoshino– Yoshino2016年07月27日 07:11:47 +00:00Commented Jul 27, 2016 at 7:11
 
You need to change
require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'Sales_OrderController.php';
to
require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'Sales'.DS.'OrderController.php';
Your code Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'Sales_OrderController.php'; generate output like
Mage/Adminhtml/controllers/Sales_OrderController.php
and which is wrong.
Also you need to change rewrite code at config.xml
in config.xml
<Mypackage_MyModule before="Mage_Adminhtml">Mypackage_MyModule_Adminhtml</Mypackage_MyModule>
controller path must be.
controllers: app\code\local\Mypackage\MyModule\controllers\Adminhtml\Sales\OrderController.php
because it will look for so the controller file will be
<?php
require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'Sales'.DS.'OrderController.php';
class Mypackage_MyModule_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
 /**
 * View order detale
 */
 public function viewAction()
 {
 $this->_title($this->__('Sales'))->_title($this->__('Orders'));
 //etc...
 }
}
 - 
 thanks for answer. I had modified these files but still don't work:(Yoshino– Yoshino2016年07月27日 07:02:10 +00:00Commented Jul 27, 2016 at 7:02
 - 
 i test this code it is working for me. check the error log.Qaisar Satti– Qaisar Satti2016年07月27日 07:17:26 +00:00Commented Jul 27, 2016 at 7:17
 - 
 It still using the core controller..app\code\core\Mage\Adminhtml\controllers\Sales\OrderController.php. I try to die some string at viewAction on this core controller. And.. it just happen...Yoshino– Yoshino2016年07月27日 07:21:55 +00:00Commented Jul 27, 2016 at 7:21
 - 
 maybe issue with camel case change module name to
Mymoduleto every place. and clear the cache or disabled is better for module creation.Qaisar Satti– Qaisar Satti2016年07月27日 07:23:56 +00:00Commented Jul 27, 2016 at 7:23