0
votes

I've done my best to figure this out, but I can't seem to get the following Controller to override in Magento:

Mage/Core/Controller/Varian/Action

Right now I have the following files for my extension:

app/local/MyCompany/MyModule/Core/Controller/Front/Action.php

app/local/MyCompany/MyModule/Core/etc/config.xml

app/etc/modules/MyCompany_MyModule.xml

My confusion lies in the config.xml. I've previously overwritten Controllers found in the controllers directory, but not the Controller. I'm not entirely clear on the difference or if the method for overriding files in the Controller directory is different.

Here's what I have in my config.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <MyCompany_MyModule>
                <version>0.0.1</version>
            </MyCompany_MyModule>
        </modules>
        <global>
            <controller>
                <Mage_Core>
                    <rewrite>
                        <front_action>MyCompany_MyModule_Core_Controller_Front_Action</front_action>
                    </rewrite>
                </Mage_Core>
            </controllers>
        </global>
    </config>

Can someone please let me know what I am missing?

3
What are you wanting to change? There may be another way.benmarks

3 Answers

4
votes

You cannot accomplish what you want via Magento configured classname rewrites. If you notice, you are changing a superclass (other classes extend from it), and the discovery of the class definition occurs through the autoloading logic from Varien_Autoload::autoload().

If you must change the definition of this class, you can copy the entire file to app/code/local/Mage/Core/Controller/Varien/ and make your changes there. You will need to merge updates to this class anytime that you upgrade Magento.

0
votes

I have also once modified Controller functions, but I think I in the end just patched the original Controller instead of overwriting it. I may be wrong, but I think Magento has no support for overwriting Controller classes.

If I recall correctly they are even called statically in the code at some points.

0
votes

Since the declaration on the magento controllers

class Mage_Catalog_ProductController extends Mage_Core_Controller_Front_Action

If was directly extends the class. What I did is replace all the controllers in somehow.

class Mage_Catalog_ProductController extends MyCompany_Core_Controller_Front_Action

To replace all controllers, I user this linux command

find app/code/core/Mage/*/controllers/ -name "*.php" -print | xargs sed -i 's/Mage_Core_Controller_Front_Action/MyCompany_Core_Controller_Front_Action/g'