1

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 Jul 27 '16 at 6:35
  • yes. I had done it. – Yoshino Jul 27 '16 at 6:58
  • It still using the core Controller: app\code\core\Mage\Adminhtml\controllers\Sales\OrderController.php. look like not working. – Yoshino Jul 27 '16 at 7:06
2

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 Jul 27 '16 at 6:52
  • error comes in log files which you can find in var\log directory. – Rajeev K Tomy Jul 27 '16 at 6:53
  • @Mokona you have your module activation file at app/etc/modules ? – Rajeev K Tomy Jul 27 '16 at 6:58
  • yeah. i had done it but still don't work – Yoshino Jul 27 '16 at 7:01
2

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.

1

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 keep Admnhtml always. – Rajeev K Tomy Jul 27 '16 at 6:51
  • yes it should be good practice to follow, so someone another programmer can easily work – liyakat Jul 27 '16 at 6:58
  • thanks for answer. I had modified these files but still don't work:( – Yoshino Jul 27 '16 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 detail – liyakat Jul 27 '16 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 Jul 27 '16 at 7:11
1

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

1

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 Jul 27 '16 at 7:02
  • i test this code it is working for me. check the error log. – Qaisar Satti Jul 27 '16 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 Jul 27 '16 at 7:21
  • maybe issue with camel case change module name to Mymodule to every place. and clear the cache or disabled is better for module creation. – Qaisar Satti Jul 27 '16 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.