Jump to content

[SOLVED] Get root category


Recommended Posts

Hi Steven

I am not sure if there is a function which currently fetches Root Names did look but could not locate one in the categories class
So I created a simple query which does what you have requested, this can easily be turned into a function but not necessary at this stage

Please follow these instructions

Insert the code below just before $smarty->assign(array( located in product.php

for example:

       if (isset($category) AND is_object($category) AND $category->id)    
       {            
           if ($category->id_parent != 1)
            $id_parent = intval($category->id_parent);
           else
            $id_parent = intval($category->id);

           $result = Db::getInstance()->ExecuteS('
           SELECT cl.`name`
           FROM `'._DB_PREFIX_.'category` c
           LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`)
           WHERE c.`id_category` = '.$id_parent.'
           ');
        // print_r($result);

           foreach ($result AS $rootCategory)
           $rootCategoryName = $rootCategory['name'];    

           $smarty->assign(array(
           'category' => $category,
           'subCategories' => $category->getSubCategories(intval($cookie->id_lang), true),
           'id_category_current' => intval($category->id),
           'id_category_parent' => intval($category->id_parent),
           'rootCategoryName' => $rootCategoryName,
           'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name))));
       }



All you do now is insert {$rootCategoryName} into product.tpl
Hope that’s what you required ;)

Link to comment
Share on other sites

×
×
  • Create New...