Accessing Overridden CategoryController via alias
-
16-10-2019 - |
Question
I have overridden the CategoryController, and can access the overridden controller using the direct URL: eg. http://myshop.dev/catalog/category This URL has the following alias associated with it: http://myshop.dev/men-s/clothing However, when accessing the alias, the original controller is used. How can I make Magento use the overridden controller here as well?
My config.xml rewrite rule is as follows:
...
<rewrite>
<rivers_controllers_catalog_view>
<from><![CDATA[#^/catalog/category/#]]></from>
<to>/riverscontroller/category/</to>
</rivers_controllers_catalog_view>
</rewrite>
Solution
Which Magento version are you using? As far as I know, this way of rewriting controllers was used in previous versions. With newest versions (>1.4), you could use the following:
<config>
<frontend>
<routers>
<catalog>
<args>
<modules>
<mynamespace_mymodule before="Mage_Catalog">Mynamespace_Mymodule</mynamespace_mymodule>
</modules>
</args>
</catalog>
</routers>
</frontend>
</config>
Now Magento will look in your controllers
folder first - notice the before
attribute - every time a request for catalog
is received. Next, place a CategoryController.php
in your controllers
folder. The class should look like this:
require_once('Mage/Catalog/controllers/CategoryController.php');
class Mynamespace_Mymodule_CategoryController extends Mage_Catalog_CategoryController
{
// Your code here
}
Don't forget to manually include the original controller, as controllers are not autoloaded by Magento.
For further reference, see also http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller