Magento has multiple features, one of its best feature is modularity and possibility of overriding core classes.
We can rewrite model classes with the use of configuration file.
Here we will see how we can override Model with the custom module.
We are taking here Magento Customer Model
as an example to rewrite model.
Step 1 : We have to rewrite app/code/core/Mage/Customer/Model/Customer.php
Step 2 : Insert <rewrite>
tag code in the file app/code/core/Mage/Customer/etc/config.xml
as shown below
<models>
<customer>
..........
<rewrite>
<customer>Magik_Customer_Model_Customer</customer>
</rewrite>
..........
</customer>
</models>
Step 3 : You need to activate custom module with following code in file app/code/local/Magik/Customer/etc/config.xml
<config>
<Magik_Customer>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Customer />
</depends>
</Magik_Customer>
</config>
Step 4 : Now we have to create file app/code/local/Magik/Customer/Model/Customer.php
as shown below.
<?php
class Magik_Customer_Model_Customer extends Mage_Customer_Model_Customer
{
// Override methods here with your own business logic
}
?>
Step 5 : Done.
If you face any problems or need our professional services, please email us at [email protected]
Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.