Magento coding tip: How to override core model class?
Piotrek KaczkowskiReading Time: < 1 minute
As a Magento developer you already know that you shouldn't mess around with core files.
So what is the best ways to edit a core model class? Override!
Let's say we would like to override core Mage_Sales_Model_Order class.
First thing you have to do is to add some lines to the config file of your module:
app/code/local/Kiwee/MyModule/etc/config.xml
And put your class name that will override core class:
<config> <global> <models> <sales> <rewrite> <order>Kiwee_MyModule_Model_Order</order> </rewrite> </sales> </models> </global> </config>
Create your class file:
app/code/local/Kiwee/MyModule/models/Order.php
And add class code to the file:
class Kiwee_MyModule_Model_Order extends Mage_Sales_Model_Order { // your code here }
Et voilà! Don't forget to clear the cache or even better disable it completely for the testing purpose.