Get Magento root category id

public function getRootCategoryId()
{
    $categories = Mage::getModel('catalog/category')->getCollection();
    $categ_ids = $categories->getAllIds();
    asort($categ_ids);
    foreach ($categ_ids as $k => $cat_id)
    {
        $category = Mage::getModel('catalog/category')->load($cat_id);
        if ($category->name)
        {
            return $cat_id;
        }
    }
}

Author: Tahir Yasin

Tahir is a Passionate Web Developer from Lahore, Pakistan and a guy with NEVER-STOP-LEARNING attitude who keeps an eye on emerging technologies and customer trends.

Leave a Reply

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