Magento – Put Category-IDs into category tree in backend

To show the category IDs in the category tree under Catalog->Categories->Manage Categories you can rewrite Mage_Adminhtml_Block_Catalog_Category_Tree in an own module. You have to rewrite the method buildNodeName like this: /** * Get category name * * @param Varien_Object $node * @return string */ public function buildNodeName($node) { $result = $this->escapeHtml($node->getName()); if ($this->_withProductCount) { $result .= ‘ (‘ . $node->getProductCount() […]

Magento – Define default values in config.xml

You can define system config value defaults in your modules config.xml like that. <?xml version=”1.0″?> <default> <myconfig_group> <settings> <test>1</test> <cronjobs>0</cronjobs> <client>0813</client> <serviceprovider>117</serviceprovider> <pricelist></pricelist> </settings> <productexport> <lux_kategorie>21</lux_kategorie> <store_view_german>1</store_view_german> <store_view_english>12</store_view_english> </productexport> </myconfig_group> </default> This sets the default value for all stores. If you want to set default values for a special store (scope), you can do it […]

Own Router or Controller

To get an own ActionController that can be called like this: http://www.mysexydomain.de/nicefrontname/nicecontrollerprefix/niceactionprefix/ … you have to add the following snippet into the FE or BE section of your config.xml: <frontend> <routers> <sns_documentmaster> <use>standard</use> <args> <module>SNS_Documentmaster</module> <frontName>nicefrontname</frontName> </args> </sns_documentmaster> </routers> </frontend>  

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”}}

Magento – Get all stores

Here is how to get all stores of your Magento instance a an Array: <?php $aAllStores = Mage::app()->getStores(); foreach ($aAllStores as $iStoreId => $oVal){ $sStoreCode = Mage::app()->getStore($iStoreId)->getCode(); $sStoreName = Mage::app()->getStore($iStoreId)->getName(); $iStoreId = Mage::app()->getStore($iStoreId)->getId(); echo $sStoreCode; echo $sStoreName; echo $iStoreId; } ?> To include the admin store you can call getStores like that: $aAllStores = Mage::app()->getStores(true) […]