Root Category in Magento

In Magento, products are assigned to Website, though we can disable the product in independent store, but this is very lengthy procedure as you need to edit each and every products.

So I came up with the solution to restrict the display of categories and products, though if you assign different Root Catalog to different store, Magento will display the categories as per the stores but not products as its assigned to website.

Below code will give all the categories belonging to Store, only precondition is that different store has different Root catalog

<?php
	$root_id = Mage::app()->getStore()->getRootCategoryId(); //get selected stores root catalog
    $category_model = Mage::getModel('catalog/category'); //get category model	     
    $root_category = $category_model->load($root_id); //load root catalog
   	$all_ids = $root_category->getChildren();  //this will give all the active subcategory of the Root Catalog   
    echo '<pre>';
    print_r($all_ids);
    echo '</pre>';   
    
	
    $all_child_categories = array();	
	$all_child_categories = $category_model->getResource()->getAllChildren($root_category);   //this will give all the subcategories of the Root Catalog   
	echo '<pre>';
	print_r($all_child_categories);
	echo '</pre>';
?>	

Hope this helps.

For loading the products please check this post Get Category Products Magento

2 thoughts on “Root Category in Magento

Leave a Reply to Murali Cancel reply

Your email address will not be published. Required fields are marked *

Scroll to top