When working on projects, you might find it useful to keep the custom code in a separate directory, and create symlinks in the Magento directory. This makes it easier to have version control and to keep tidy the Magento base directory.

A custom project directory looks something like this:

myproject/app/etc/modules
myproject/app/design/frontend/default/mytheme
myproject/app/code/local

To install a custom front-end theme, I will just create a symbolic link in the appropriate directory, e.g.:

cd <magento base>/app/design/frontend/default
ln -s /path/to/myproject/app/design/frontend/default/mytheme

This used to work without any issues up until version 1.4.2.0, when there was a filesystem check added to the method that loads the template file, i.e.

--- magento-1411/app/code/core/Mage/Core/Block/Template.php	2010-07-26 22:08:55.000000000 +0200
+++ magento-1420/app/code/core/Mage/Core/Block/Template.php	2010-12-08 22:12:05.000000000 +0100
@@ -194,7 +194,9 @@
     {
         Varien_Profiler::start($fileName);

-        extract ($this->_viewVars);
+        // EXTR_SKIP protects from overriding
+        // already defined variables
+        extract ($this->_viewVars, EXTR_SKIP);
         $do = $this->getDirectOutput();

         if (!$do) {
@@ -209,7 +211,13 @@
         }

         try {
-            include $this->_viewDir . DS . $fileName;
+            $includeFilePath = realpath($this->_viewDir . DS . $fileName);
+            if (strpos($includeFilePath, realpath($this->_viewDir)) === 0) {
+                include $includeFilePath;
+            } else {
+                Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);
+            }
+
         } catch (Exception $e) {
             ob_get_clean();
             throw $e;

This check will not allow using templates outside of the app/design directory (you can see in the system.log something like this: “CRIT (2): Not valid template file:frontend/default/mtp/template/catalog/product/price.phtml”). Here are some possible fixes:

1. override Mage_Core_Block_Template by creating the directory structure: app/code/local/Mage/Core/Block and copy Template.php from  app/code/core/Mage/Core/Block and removing the code that checks the template directory (see diff above)

2. use the mount –bind command, to mount your custom directory in app/design

cd <magento base>/app/design/frontend/default
mkdir mytheme
sudo mount --bind /path/to/myproject/app/design/frontend/default/mytheme mytheme

Unfortunately the –bind option is not available on OSX.

[later edit]

As of version 1.5.1.0-rc1 there is a config flag that you can set to allow symlinks for template files. In the back-end go to system configuration, developer settings and enable “Allow Symlinks” from “Template settings”. Or you can programmatically set the config defaults from the local.xml or your custom extension config.xml

<config>
    <default>
        <dev>
            <template>
                <allow_symlink>1</allow_symlink>
            </template>
        </dev>
    </default>
</config>

Happy coding.

Resources:

http://stackoverflow.com/questions/4473654/magento-zend-not-allowing-symbolic-links
http://www.magentocommerce.com/bug-tracking/issue/?issue=10487
http://code.google.com/p/module-manager/
http://alanstorm.com/magento_default_system_configuration_values

During Magento development you will find yourself repeating certain tasks over and over again, and some of them can start to take a lot of your development time, e.g. clearing cache, enable/disable path hints, change config values. Now there’s a command line utility that can help you do all of these tedious tasks in no time. MageTool to the rescue!

Install MageTool

pear channel-discover pear.zfcampus.org
pear channel-discover pear.magetool.co.uk
pear install magetool/MageTool-beta

Create in your home directory a .zf.ini file and add the following:

basicloader.classes.1 = "MageTool_Tool_MageApp_Provider_Manifest"
basicloader.classes.2 = "MageTool_Tool_MageExtension_Provider_Manifest"

Now you’re ready to start testing all the new zf commands. Go to your Magento directory and give it a try.

Clear Magento cache

zf clear mage-core-cache

Enable/Disable Magento cache

zf [enable/disable] mage-core-cache

Enable/Disable template path hints

zf set mage-core-config dev/debug/template_hints stores --value [1/0]

Read how to enable template path hints in the admin


Create bare Magento extension

zf create mage-extension Yourdomaincom CoolExtension local

Show all config values or filter for keyword

zf show mage-core-config
zf show mage-core-config web

Get a single config value

zf show mage-core-config web/unsecure/base_url

Set a config value

zf set mage-core-config web/unsecure/base_url --value=http://www.example.com/ --scope=default

Make it easier, use bash autocompletion

Get the magetool bash autocompletion from GitHub. To use it on Ubuntu copy it to /etc/bash_completion.d/

/magento$ zf show mage-
mage-admin-user     mage-core-config    mage-core-resource

You can also create some bash aliases, e.g.

alias mage_cc='zf clear mage-core-cache'

Hope this will make your life a bit easier.

Resources
http://magetool.co.uk
http://www.designdisclosure.com/2010/10/magento-command-line-tools-magetool/

top