[Solved]Magento 1.9 Override RoundPrice
-
05-02-2021 - |
Question
Vers. Magento 1.9.3.9
I need to override thi function from Mage_Core_Model_Store
public function roundPrice($price)
{
return round($price, 2);
}
So I created e new module:
app/etc/modules/MyCompany.xml
<config>
<modules>
<MyCompany_RoundPrice>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Core />
</depends>
</MyCompany_RoundPrice>
</modules>
</config>
app/code/local/MyCompany/RoundPrice/etc/config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<MyCompany_RoundPrice>
<version>0.1.0</version>
</MyCompany_RoundPrice>
</modules>
<global>
<models>
<roundprice>
<class>MyCompany_RoundPrice_Model</class>
</roundprice>
<core>
<rewrite>
<store>MyCompany_RoundPrice_Model_Store</store>
</rewrite>
</core>
</models>
</global>
</config>
app/code/local/MyCompany/RoundPrice/Model/Store.php
<?php
class MyCompany_RoundPrice_Model_Store extends Mage_Core_Model_Store
{
public function roundPrice($price)
{
return round($price, 4);
}
}
It should work but it doesn't.
What is wrong???
EDIT
Some tests:
echo Mage::helper('core')->isModuleEnabled('MyCompany_RoundPrice').'<br />'; //output 1
echo Mage::helper('core')->isModuleOutputEnabled('MyCompany_RoundPrice').'<br />'; //output 1
echo Mage::getModel('roundprice/store')->roundPrice(1.23456789); //output 1.2347
echo Mage::getModel('core/store')->roundPrice(1.23456789); //output 1.23
The module is active and reachable, but doesn't override the core file.
Solution 2
Same old story
There was another module that already override Mage_Core_Model_Store
So i needed to modify app/etc/modules/MyCompany.xml as follow:
<config>
<modules>
<MyCompany_RoundPrice>
<active>true</active>
<codePool>local</codePool>
<depends>
<Other_Module />
</depends>
</MyCompany_RoundPrice>
</modules>
</config>
Now it works.
OTHER TIPS
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
In this way you can override it.