Magento – rewrite a controller that is already rewriting another

controllersoverrides

Is it possible to rewrite a controller in a community module that is already rewriting a core controller?

I have the syntax correct as it is working in other rewrites but in this specific case the rewrite is not working.

There is a community module rewriting the cart controller and i want to rewrite the community modules cart controller.

It would be like this:

My Controller -> Community Modules cart controller -> Mage Cart controller

Best Answer

This may depend on how the extension is overriding the controller but here goes. You need to add in your module's config.xml file, this as a child of the <config> node.

<frontend>
    <routers>
        <checkout>
            <args>
                <modules>
                    <Your_ModuleNameHere before="Community_ModuleNameHere">Your_ModuleNameHere</Your_ModuleNameHere>
                </modules>
            </args>
        </checkout>
    </routers>
</frontend>

If the community module overrides the cart controller in the same way as described above then it works. If it uses the 'old method' with <from> and <to> tags then it won't work.
(and I have no idea on how to override that).

[EDIT]
Make sure that your controller is also named CartController and it's located in Namespace/Module/controllers/CartController.php. Also you might want to make your local module depend on the community module but I don't think this is mandatory. Also make your controller class extend the community module controller.

Related Topic