How to override sales block and model
Posted Date: January 27, 2010I was just working on the Sales module to override block and model classes.
I though it would be very good to share it with others as well.
So, here it is and let’s do it step by step:
Step 1:
Create new module in local folder with your preferred name, in my case I am going to keep it same “Salesâ€.
Step 2:
Add etc folder and add the config.xml file with the following code which will tell magento to override block and model.
<?xml version="1.0" encoding="utf-8"?> <config> <modules> <Mycompany_Sales> <version>0.1.0</version> </Mycompany_Sales> </modules> <global> <models> <sales> <rewrite> <quote_address_total_shipping>Mycompany_Sales_Model_Quote_Address_Total_Shipping</quote_address_total_shipping> </rewrite> </sales> </models> <blocks> <sales> <rewrite> <order_email_items_default>Mycompany_Sales_Block_Order_Email_Items_Default</order_email_items_default> </rewrite> </sales> </blocks> </global> <default> <config_vars /> </default> </config>
Step 3:
Now the next step is to create the classes for block and model class in the specified locations:
In the above file I have mention the below line:
M4U_Sales_Model_Quote_Address_Total_Shipping
So, you need to follow the above line and create the folders structure like that:
Quote->Address->Total->Shipping.php
And you can follow same structure for blocks directory structure.
Step 4:
Add the reference of this module into
App->etc->modules->mycompany_all.xml
CLICK HERE to download the complete source.

