Compress and extract files

With tar On Unix based plattforms you can use the tar command for file compression and also for later uncompression. Compression $> tar -pczf web.tar.gz web/ With -h as the first parameter the real files instead symbolic links are compressed. So you can tar symbolic link targets. To exclude files or folder, you can define –exclude=’fileOFolderPath’ directly […]

Conditions

There are conditional commands for MySQL too. IF/ELSE SELECT FieldA as A, FieldB as B, IF(FieldA = FieldB, ‘equal’, ‘not equal’) as condition, FROM table WHERE this LIKE that Or cascaded: SELECT FieldA as A, FieldB as B, IF(FieldA = FieldB,’FieldA is equal to FieldB’,IF(FieldC = FieldD,’FieldC is equal to FieldD’,’all false’)) as output, FROM […]

Event Observer

The following snippet have to be added to the config.xml under the frontend (for FE-events) – or the adminhtml (for BE-Events) – tag: <events> <event_name> <observers> <observer_unique_config_name> <!– singleton or model –> <type>singleton</type> <class>Namespace_Modul_Model_Modelname</class> <method>functionToCallOnModelClassInstance</method> </observer_unique_config_name> </observers> </event_name> </events>  

Add JavaScript or CSS in Block class

 To add JavaScript or CSS files to the head section of the resulting HTML page, you can add something like this to the _prepareLayout function of a Block class: $headBlock = $this->getLayout()->getBlock(‘head’); $headBlock->addJs(‘somefolder/ask-sheldon.js’); $headBlock->addCss(‘somefolder/ask-sheldon.css’); As you can see, we can use the layout model to get the head block an use its functions to add files. This […]

Automatically load custom product attribute with collection (every time)

You can do this with the following XML in your config.xml: <frontend> <product> <collection> <attributes> <ATTRIBUTECODE/> </attributes> </collection> </product> </frontend> But ATTENTION: This can become a performance issue, because it loads the attribute every time the product collection is loaded! If you added too many attributes, the performance can get worse!  

Add breadcrump in custom block

This is how to add a Breadcrumb entry in an own block: $breadcrumbs = $this->getLayout()->getBlock(‘breadcrumbs’); $breadcrumbs->addCrumb(‘home’, array(‘label’=>Mage::helper(‘cms’)->__(‘Home’), ‘title’=>Mage::helper(‘cms’)->__(‘Go to Home Page’), ‘link’=>Mage::getBaseUrl())); $breadcrumbs->addCrumb(‘cms_page’, array(‘label’=>$page->getTitle(), ‘title’=>$page->getTitle()));

Add static block to cms page

First, you can use the XML-Layout-Update of the respective page (or other layout updates in every layout xml file ): <reference name=”content oder right oder left”> <block type=”cms/block” name=”blockname”> <action method=”setBlockId”><id>BLOCK-ID</id></action> </block> </reference> Or you can use the following placeholder: {{block type=”cms/block” block_id=”BLOCK-ID” template=”cms/content.phtml”}}