Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to change the default url of any block in magento?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 338
    Comment on it

    Suppose, we are required to change the url of any block in magento, lets see how we can change the url.


    To do so we have to create a module and then re-write the url of that block path to redirect to the module. lets create a module first :


    Lest we need to change the path of the 'checkout/cart' url with the '/bag' we need to do it with the module.


    1. Create a module with namespace and modulename, set the module name as 'bag'.
    2. Then Create a file config.xml in etc folder in our module.
    3. Then in the model folder of our module, at the path local/namespace/Bag/Model/Core create a class file url.php


    Now, in our config.xml file at the path Namespace/Bag/etc/config.xml write the below code in it :

            <![CDATA[ #^/checkout/cart# ]]>


    In the above code in global we have <rewrite> tag in which at the "checkout/cart" request we are changing the request to "bag".
    and then in the model we called our model class file url.php


    Now, in the Model file write the below code:


    class Namespace_Bag_Model_Core_Url extends Mage_Core_Model_Url {
      public function getUrl($routePath = null, $routeParams = null) {
        if ( $routePath == 'checkout/cart' ) {
          $routePath = 'bag';
        return parent::getUrl($routePath, $routeParams);

    In the above class file code we are building the url with the requested path and parameters by extending the core class Mage_Core_Model_Url.
    the $routePath is a string which catches the target path and then we matches it with the desired path "checkout/cart" in the if condition, if it gets matched then we replace the route path of the parameter $routeParams to "bag". Then finally we return the url.


    Afterwards, we need to rewrite the path from the backend to our module path for that login to the admin panel in catalog-> Url Rewrite Management  go to the "Add url Rewrite" and select the "custom" from "Create URL Rewrite:" options.
    Then in the Id Path give an unique identifier, now in field "Request Path" set it to "bag" and the "Target Path" write "checkout/cart" and save it.


    Now, to check in url hit http://localhost/YourSiteName/index.php/bag you will get redirect to the checkout/cart page with the changed url.
    In the same way you can perform it to change the url of any page or block in magento.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: