Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Overriding Magento Core Files

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 422
    Comment on it

    Hello Readers,
    Sometimes you need to do some changes in magento core files. It is a good habit of every Magento programmer to override the core file instead of making change in core file.
    In this tutorial, i will explain how to override magento blocks, controllers & Models.

    Overriding Magento Blocks
    Path: "app/code/local/Namespace/Module/etc/config.xml" and paste the following contents in that file.

    <config>
    
     <global>
    
          <blocks>
    
               <catalog>
    
                <rewrite>
    
                 <view>Namespace_Module_Block_View</view>
    
                </rewrite>
    
               </catalog>
    
        </blocks>
    
     </global>
    
    </config>

    Now, create a block file "app/code/local/Namespace/Module/block/View.php"

    class Namespace_Module_Block_View extends Mage_Catalog_Block_Category_View
    
    {
    
    public function getProductListHtml()
    
      {
    
    
        return $this>getChildHtml('product_list');
    
      }
    
    }

    Override Magento Controllers:
    Path: "app/code/local/Namespace/Module/etc/config.xml"

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

    Now, create a controller file "app/code/local/Namespace/Module/controllers/CartController.php" and paste the following contents in that file.

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


    Overriding Magento Models

    (path of config file of your custom module ):
    Path: "app/code/local/Namespace/Module/etc/config.xml" and paste the following contents in that file.

    <config>
      <global>
    
     <models>
    
           <checkout>
    
            <rewrite>
    
                 <cart>Namespace_Module_Model_Cart</cart>
    
            </rewrite>
    
           </checkout>
    
     </models>
    
     </global>
    
    </config>

    Now, create a Model file "app/code/local/Namespace/Module/Model/Cart.php" and paste the following contents in that file.
     

    class Namespace_Module_Model_Cart extends Mage_Checkout_Model_Cart
    
    {
    
    // override code in new class
    
    }

     

 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: