How to create a local copy of app/code/core/Mage/

Last modified by dd_gi on Fri, June 25, 2010 09:05
Source|Old Revisions  

This is an old revision of the document!

At times you may find that you will see a post in the Magento forums that recommends that you edit a “local” copy of a given Mangento core file such as app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php

The recommendation to edit a local copy of a core file is so that when you upgrade to a new version of Magento the core file you edited will be overwritten and you will lose your changes.

How the local folder works

Core files in the local folder override the same files in the core folder. For example, if you copy app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php to app/code/local/Mage/Catalog/Model/Layer/Filter/Price.php then Magento will use app/code/local/Mage/Catalog/Model/Layer/Filter/Price.php

The complication is that the app/code/local/* folders are not created by default, so if you would attempt to copy the file in an ssh session etc. the copy would fail since the enclosing folders have not been created.

How to create the local folder structure

You could just create folders as need, for example if you wanted to create a local copy of app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php you would first create the “/app/code/local/” folder if it did not exist, then inside app/code/local/ you would create a “Mage” folder and so on.

With PHP 5 and up you can create a complete directory structure with one mkdir command as it now has a recursive option, as well you can set permissions during that process.

To make that task easier I created a PHP script to duplicate the /app/code/core/Mage/ folder structure to /app/code/local/Mage/ and set the permissions to 777 (world readable,writeable,executable) during creation.

If world WRX is too open for your security structure please modify that value accordingly. If you are curious about what other values are acceptable, Google for “online chmod calculator”.

Note that the script creates a folder only if it has not been created, if a local folder or subfolder exists now it does not create it nor does it modify any contents, it simply creates folders under /app/code/local/Mage/ if they do not exist.

How to use the script

First, create a new file named createlocal.php within your app/code/ folder within your Magento root folder. Copy the following code and paste into that file, then open it within a web browser using http://yourdomain/yourmagentorootfolder/createlocal.php and you should see lines of folders stating “creating:...” or “exists:” for each folder/subfolder, then finally you will see a “process complete.” message.

The script


Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs