I want to override an core model class, but I cannot find the correct way to do it.
I have googled a lot, but some of the examples are shown how to override a model which are not located at app/code/core/Mage/Core/Model
folder and some of the examples are shown how to override a model which in the sub-dir of Core
dir, like app/code/core/Mage/Core/Model/Resources/Eav/Mysql4/
.
I have read the examples, but I still cannot find a way to override it. For example, I want to override app/code/core/Mage/Core/Model/Store.php
And here is the xml I use, but it is not working. Please help me to find out which part is wrong. Thanks in advance!
app/etc/models/My_Core
<config>
<modules>
<My_Core>
<active>true</active>
<codePool>local</codePool>
</My_Core>
</modules>
</config>
app/code/local/My/Core/etc/config.xml
<config>
<modules>
<My_Core>
<version>0.1.0</version>
</My_Core>
</modules>
<global>
<models>
<my_core_store>
<rewrite>
<class>My_Core_Model_Store</class>
</rewrite>
</my_core_store>
</models>
</global>
</config>
The new Store.php file is at app/code/local/My/Core/Model/Store.php
. And the magento version is 1.8.1.0
Your config.xml has some mistakes. Follow in this way..
< ?xml version="1.0"?>
<config>
<modules>
<my_core>
<version>0.1.0</version>
</my_core>
</modules>
<global>
<models>
<core>
<rewrite>
<store>My_Core_Model_Store</Store>
</rewrite>
</core>
</models>
</global>
</config>
and also in the model class, You need to extend the Parent Class Name. For Ex: My_Core_Model_Filename extends Mage_Core_Model_Store
For most of them it will be
<modulename>
<rewrite><path_to_file>My_Extension_Path_To_Extended_File</path_to_file>
</modulename>
So in your case it would be
<core>
<rewrite><store>My_Core_Model_Store</store></rewrite>
</core>
Although, note that for Mysql4 or Resource files, they are defined under modulename_mysql4
or modulename_resource
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With