Jump to content

Get default category name


Recommended Posts

Given any id_category, how can i know the name of its default category(where id_parent = 1)?

Is there any function in which i can pass any category id and it returns name of corresponding default category?

Link to comment
Share on other sites

This can be a solution if ever some1 needs it.

public static function getFirstParentCategories($idLang, $id_cat)
               $categories = null;

               while (true)
                   $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
                       SELECT c.*, cl.*
                       FROM `'._DB_PREFIX_.'category` c
                       LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)($idLang).')
                       WHERE c.`id_category` = '.(int)$id_cat.' AND c.`id_parent` != 0

                   $categories[] = $result[0];
                   if(!$result OR $result[0]['id_parent'] == 1)
                       return $result;
                   $id_cat = $result[0]['id_parent'];

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...