Ace and king cards being checked during poker game

Magento coding tip: How to override core model class?

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.

FacebookTwitterPinterest

Piotr Kaczkowski

Senior Full Stack Developer

My adventure with computers started when my parents bought our first PC, I was about 10 at the time. At first I was just playing games but after a while I became interested in programming. Starting with Turbo Pascal and Assembler then moved to C++ and PHP.