0

I'm trying to extend the mage order controller, but i'm getting a 404 error. As far as i can tell my custom ordercontroller is not being included. I've read multiple Q&A's on stackexchange but i can't find anything out of the ordinary in my code.

Below is how my module is build up:

app/etc/modules/Bromo_Orderstatus.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Bromo_Orderstatus>
            <active>true</active>
            <codePool>local</codePool>
        </Bromo_Orderstatus>
    </modules>
</config>

app/code/local/Bromo/Orderstatus/etc/config.xml

<config>
    <modules>
        <Bromo_Orderstatus>
            <version>1.0.0</version>
        </Bromo_Orderstatus>
    </modules>
    <global>
        <blocks>
             <adminhtml>
                <rewrite>
                    <sales_order_view>Bromo_Orderstatus_Block_Adminhtml_Sales_Order_View</sales_order_view>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <use>admin</use>
                <args>
                    <modules>
                        <orderstatus before="Mage_Adminhtml_Sales">Bromo_Orderstatus_Adminhtml</orderstatus>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

app/code/local/Bromo/Orderstatus/Block/Adminhtml/Sales/Order/View.php

<?php
class Bromo_Orderstatus_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
    public function  __construct() {
        $message = Mage::helper('sales')->__('Weet je zeker dat je de klant een klaar voor afhalen e-mail wil versturen?');
        $this->_addButton('afhalenmail', array(
            'label'     => Mage::helper('Sales')->__('Stuur afhaal E-mail (nog niet gebruiken!)'),
            'onclick'   => "confirmSetLocation('{$message}', '{$this->getUrl('*/*/afhalenmail')}')"
            ));
        parent::__construct();
    }   
}

app/code/local/Bromo/Orderstatus/controllers/Adminhtml/Sales/OrderController.php

<?php
require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';

class Bromo_Orderstatus_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController {

    public function afhalenmailAction() {

         echo 'Test action';

    }

}

Who would be so kind to be able to tell me what i'm missing here?

Edit1: The button is showing absolutely fine, works too (goes to the correct page with showing an confirm message beforehand). Cache etc has already been refreshed.

The problem lays somewhere in my custom controller not being called or some sort.

6
  • I've edited the post, the link you've marked as possible duplicate is having a different problem then mine. I don't understand why this should be the same as my problem?
    – Tobias
    Jul 29, 2016 at 12:47
  • I see, it could indeed explain why my controller is not being included because a different module is already rewriting the original one. Seems this is a bad way of rewriting controllers then. If i want to do this the unclean way i'll just have to find that module which is rewriting it, or find another method (if there's any) to do it cleaner.
    – Tobias
    Jul 29, 2016 at 13:11
  • i don't see that problem in you case you have problem with xml <Bromo_Orderstatus before="Mage_Adminhtml">Bromo_Orderstatus_Adminhtml</Bromo_Orderstatus> add this line and check Jul 29, 2016 at 13:17
  • 1
    Possible duplicate of Magento: add button on order view page with custom module Aug 13, 2016 at 18:53

2 Answers 2

2

Change below code:

<admin>
        <routers>
            <adminhtml>
                <use>admin</use>
                <args>
                    <modules>
                        <orderstatus before="Mage_Adminhtml_Sales">Bromo_Orderstatus_Adminhtml</orderstatus>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

to:

<admin>
        <routers>
            <adminhtml>
                <use>admin</use>
                <args>
                    <modules>
                        <orderstatus before="Mage_Adminhtml">Bromo_Orderstatus_Adminhtml</orderstatus>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

Change controller code as below:

<?php
require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';

class Bromo_Orderstatus_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController {

    public function afhalenmailAction() {

         echo 'Test action';

    }

}
2
  • Maybe i'm missing something in your answer, but why would rewriting the class path's to something different be better? The only thing it does is not being the same as the original paths, which in my opinion is not a clean way. Correct me if i'm wrong though!
    – Tobias
    Jul 29, 2016 at 13:16
  • 2
    @Tobias the reason is due to how routes are matched. Frontnames (the first part of the route) are primarily owned by a module, identified by module="Mage_Adminhtml" in configuration. From there it's a matter of matching the rest of the routing params, namely the path to the controller file and the action name. However, Prashant's answer isn't quite correct, because the path under your controllers directory has to match the path under the Adminhtml module, i.e. Bromo/Orderstatus/controllers/Adminhtml/Sales/OrderController.php assuming you adjust the classname to match.
    – benmarks
    Aug 2, 2016 at 19:37
0

So i figured out that it was indeed a module who was overwriting the original controller. I missed this module since i believed it was uninstalled properly (except it wasn't). Removed this module in the first place since it was leaving data all over the place in the first place.

Anyhow after i removed the module's remaining files the controller extending was working as it should be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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