tags:

views:

67

answers:

3

I would like to make changes to some Magento core files. To make sure the changes are future proof I copy the file from code/core/Mage to code/local/Mage.

I keep the file structures and file names consistent. The problem is when I do this the changes have no effect (I've refreshed the cache)

Any ideas where I'm going wrong? If I edit the core files directly the changes take place.

+2  A: 

You should create a new local module and define rewrites in the config.xml file:

Create app/code/local/MyCompany/MyModule directory. Add subfolders etc and model.

Now create etc/config.xml file containing:

<?xml version="1.0" encoding="utf-8?>
<config>
    <modules>
        <MyCompany_MyModule>
            <version>0.1.0</version>
        </MyCompany_MyModule>
    </modules>

    <global>
         <models> <!-- type of class to rewrite -->
            <catalog> <!-- base module to rewrite -->
                <rewrite>
                    <product>MyCompany_MyModule_Model_Product</product>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

Implement model/Product.php with your changes. Easiest way is to inherit from the base class and rewrite the metho.

Also remember to activate your module in app/etc/modules.

Janus Tøndering
A: 

The above poster is correct in that the preferred way to edit core functionality is to use rewrites. In some cases, though, this isn't possible, in which case you should be able to place core files into the /app/code/local/Mage directory to get them to work. Block and Model files should work immediately in this way, as should controllers if I remember correctly. Other files (such as config files) may not be automatic.

Could you post the details of a particular file that doesn't respond as you expect? It's easier to debug particulars than generalities. Also, make sure that you have shut off any opcode cache that you have installed on the server in addition to flushing the normal cache.

Thanks, Joe

Joseph Mastey
With config files you just place the overwrites verbatim in your modules config.xml or in local.xml.
Janus Tøndering
You can't overwrite classes that are not instantiated the Mage class. So, stuff like Mage_Model_Catalog_Product_Abstract can't be done this way. Basically, it doesn't work with inheritance since the "normal" class name is used here.
Janus Tøndering
The file I was trying to edit was:app > code > core > Mage > Customer > etc > config.xmlI tried copying it to: app > code > local > Mage > Customer > etc > config.xml
a1anm
A: 

You can easily overwrite xml settings using local.xml. So, if you want to overwrite/add to app/code/core/Mage/Customer/etc/config.xml you just add it to app/etc/local.xml.

Janus Tøndering