Steven C. Day Posted September 29, 2008 Share Posted September 29, 2008 Is there a function built into PrestaShop that will give me the top-level category for any given product?For example:Men's->Apparel ->Shirts ->Red X-Large Polo (id_product = 56)If I had the id_product (56), I could get the ID of "Men's"Any thoughts? Link to comment Share on other sites More sharing options...
ejectcore Posted October 5, 2008 Share Posted October 5, 2008 Hi StevenI am not sure if there is a function which currently fetches Root Names did look but could not locate one in the categories classSo I created a simple query which does what you have requested, this can easily be turned into a function but not necessary at this stagePlease follow these instructionsInsert the code below just before $smarty->assign(array( located in product.phpfor 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.tplHope that’s what you required Link to comment Share on other sites More sharing options...
Recommended Posts