Magento :Difference between Override and Rewrite

As Magento says don’t change the core files, so there are two ways you can change core files and for Block/Helper/Model classes.

Definations:-

  • Override :

When we use design fallback mechanism then we are doing override

  • Rewrite :

When we rewrite magento Core classes in our class then we are doing rewrite.

Example of Override :

If i need to override app/code/core/Mage/Catalog/Block/Product/List.php file then I copy in my local module with same path shown below app/code/local/Mage/Catalog/Block/Product/List.php

Note :- This is not Suggested By magento But you can do that way.

Example Of Rewrite :

If I want to rewrite this block class Mage_Adminhtml_Block_Sales_Order_Create then I code in my module config.xml Like Below.

   <global>
        <blocks>
            <adminhtml>
                <rewrite>
                   <sales_order_create>Trimantra_Smallchanges_Block_Adminhtml_Sales_Order_Create</sales_order_create>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>

And In my class Trimantra_Smallchanges_Block_Adminhtml_Sales_Order_Create

I code Like Below

class Trimantra_Smallchanges_Block_Adminhtml_Sales_Order_Create extends Mage_Adminhtml_Block_Sales_Order_Create {
           //My Function Or funcions That I want to Rewrite..
}

These are two ways we can customize core classes without changing core files

Leave a Reply

Your email address will not be published. Required fields are marked *