Page tree
Skip to end of metadata
Go to start of metadata

When searching through the forums (thank goodness for the forums) you will see posts that recommend 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 copyapp/code/core/Mage/Catalog/Model/Layer/Filter/Price.php toapp/code/local/Mage/Catalog/Model/Layer/Filter/Price.php then Magento will useapp/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 ofapp/code/core/Mage/Catalog/Model/Layer/Filter/Price.php you would first create the local folder if it did not exist, then inside 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


Before running any script is important to understand what it does, if you don’t understand the PHP commands used below then please research them at before running the script, or better yet, just don’t run the script. As with running any code against your Magento directory structure, make sure you have a complete backup of your files/folders before running the script.

First, create a new file named createlocal.php 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

Purpose: To duplicate the app/code/core/Mage/ folder
         (folders only, no files) structure
         to /app/code/local/Mage/
function dupCodeDirsNoFiles($dir) {
    global $root;
    $listing = opendir($dir);
    while(($entry = readdir($listing)) !== false) {
        if ($entry != "." && $entry != "..") {
            $coreItem = "$dir/$entry";
            if (is_dir($coreItem)) {
                    echo "Creating: $localItem";
                    $old_umask = umask(0);
                } else {
                    echo "Exists: $localItem";
    echo "Process Complete.";
} else {
    echo "Please verify that you have this script in the root folder of your Magento installation.";
  • No labels