Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Override Magento Controllers

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 83
    Comment on it

    In this blog post, i will explain how to override magento controllers.
    As per magento best practices, we should not change any core files.

    So, what we will do is, create a new module called My_Pant and then we will perform our task to override.
    Remember: it is a bad programming if core files are modified.
    Create config.xml file of your custom module.

    Path: "app/code/local/Namespace/Modulename/etc/config.xml" and paste the following contents in that file.
    lets suppose namespace is My & module is Pant

    <config>
    
     <frontend>
        <routers>
                <checkout>
                    <args>
                        <modules>
                            <My_Pant before="Mage_Checkout">My_Pant</My_Pant>
                        </modules>
                    </args>
                </checkout>
            </routers>
    
     </frontend>
    
    </config>

    <My_Pant before="Mage_Checkout">My_Pant</My_Pant> tag will load our custom module's controller files if available.
    Now, create a controller file "app/code/local/My/Pant/controllers/CartController.php" and paste the following contents in that file.
     

    <?php
    
    require_once 'Mage/Checkout/controllers/CartController.php';
    class My_Pant_CartController extends Mage_Checkout_CartController
    
    {
    
    // some code
    
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: