2

Now every catalog url rewrites to catalog\category\view. But I would like to rewrite it to my own controller. Is there any simple way to do it?

  • You can just override the view method of the category controller. – Marius Jul 8 '14 at 7:55
  • By extending the Mage_Core_Controller_Varien_Router_Abstract Router class in your module you can rewrite catalog Url to your own controller's action for e.g you can refer Mage_CMS module. – sandip.vaghasiya Jul 8 '14 at 8:01
2

create config.xml app/code/local/ MyNameSpace/MyModule/etc. and past below code:

   <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <modules>
            <MyNameSpace_MyModule>
                <version>0.1.0</version>
            </MyNameSpace_MyModule>
        </modules>

        <frontend>
            <routers>
                <checkout>
                    <args>
                        <modules>
                            <MyNameSpace_MyModule before="Mage_Catalog">MyNameSpace_MyModule</MyNameSpace_MyModule>
                        </modules>
                    </args>
                </checkout>
            </routers>
        </frontend>
    </config>

create file under app/code/local/MyNameSpace/MyModule/controllers/CategoryController.php and put the below code

<?php    
require_once Mage::getModuleDir('controllers', 'Mage_Catalog').DS.'CategoryController.php';
    class MyNameSpace_MyModule_CategoryController extends Mage_Catalog_CategoryController
    {
       public function viewAction()
       {
           Mage::log("controller..");
           parent::viewAction();
       }
    }

Create module file under app/etc/modules/MyNameSpace_MyModule.xml and it code is below

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <MyNameSpace_MyModule>
            <codePool>local</codePool>
            <active>true</active>
        </MyNameSpace_MyModule>
    </modules>
</config>

More details http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller

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.