Thursday, August 9, 2012

adding link to magento top menu using layout update


Add link to Magento Top Menu using Layout XML update
in your custom module's  layout.xml default handle add this


      <reference name="root">
            <reference name="top.links">
                <action method="addLink" translate="label title">
                    <label>About Us</label>
                    <url>about</url>  <!-- can use full url also -->
                    <title>About Us</title>
                    <prepare>true</prepare> <!-- set true if adding base url param -->
                    <urlParams helper="core/url/getHomeUrl"/>
                </action>
            </reference>
        </reference>

Using IF-ELSE OR CASE-WHEN in Magento Collection - Expression based field by addExpressionAttributeToSelect

Using IF-ELSE OR CASE-WHEN  in Magento Collection - Expression based temporary column field  by addExpressionAttributeToSelect

Magento addExpressionAttributeToSelect  method can be used to create temporary column in
collections

$_collection Mage::getResourceModel('sales/order_collection')
        ->
addExpressionAttributeToSelect('your_temp_column''CASE order_id WHEN 1 THEN one ELSE TWO END ''');

on printing sql query using getselect
echo $_collection->getSelect() ;


 the magento will create query something like this  SELECT (CASE order_id WHEN 1 THEN one ELSE TWO END) AS your_temp_column

The temproary column can be used for sorting and filtering also , please note for filtering
you need to use 'having'  instead of builtin addAttributeToFilter method.
$_collection->getSelect()->having('your_temp_column = "one" '); 

hope this helps