0

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.

  • I think you should create same folder structure like core means in your local folder create core->mage->store then put your files there it should work. – Shubham Khandelwal Oct 24 '18 at 3:32
  • Sure, but than i'll override the whole class, not just that function – krybbio Oct 24 '18 at 3:37
  • yes exactly you can go through this link too stackoverflow.com/questions/5978153/… – Shubham Khandelwal Oct 24 '18 at 3:40
  • This is not what i need. I DON'T want to ovverride the whole class. Keep reading stackoverflow.com/a/5991786/5065206 – krybbio Oct 24 '18 at 3:42
  • the link which i shared is useful for your answer if you want to use the core functionality with some modification then you need to copy that same file structure in your local why? because we know the magento fallback structure it always go to our local folder first then into core if you use the class then how it will use the local files it always go to core files. – Shubham Khandelwal Oct 24 '18 at 3:46
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

In this way you can override it.

  • Can you please tell me what is wrong in my config.xml? I cannot see. – krybbio Oct 24 '18 at 4:05
  • @krybbio no need to overwrite tag and inner content. Just try it. It will work for me. – Mayur Oct 24 '18 at 4:08
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.