Thursday 26 July 2012

Magento: Find subcategories for a particular root category


We can use the below code to find all child categories for a particular root category in Magento


<?php
   
   //get category model

    $category_model = Mage::getModel('catalog/category'); 

 //$categoryid for which we have to find the child categories (root category id   or other parent category id)

    $_category = $category_model->load($categoryid); 

 //array that contains all child categories id
        
$all_child_categories = $category_model->getResource()->getAllChildren($_category);

foreach($all_child_categories as $childcatId)
{
   echo $childcatId; //// here you get child categories id
}

?>

Friday 13 July 2012

How to set different themes for logged in users?

Now you can change your magento theme for different users like logged in user and guest user

1. got to design/frontend/default/You theme/template/page
 find 1column.phtml,2columns-left.phtml,2columns-right.phtml,3columns.phtml,empty.phtml in all this files put below code above <html> tag


<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()):
Mage::getDesign()->setPackageName('package_name')->setTheme('themename');
endif;
?>

ex.
if you put code like this


<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()):
Mage::getDesign()->setPackageName('default')->setTheme('modern');
endif;
?>
than if user logged in site that time theme change to modern them and for guest user site theme is default that you set,
here instade of modern you can use your own theme so you store theme change according to user

may this post help you,
thank you....