Sharak Posted April 30, 2014 Share Posted April 30, 2014 (edited) I want to get specific category information by category_id on every page, not only category or product related. No problem with link, I just use i.e. {$link->getCategoryLink('12')} where 12 is category ID. But how to get category name? Is there any global function for that? Edited July 11, 2014 by Sharak (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted April 30, 2014 Share Posted April 30, 2014 You can't. The only solution is doing it from a php file. You can either create a new method, or instantiate the category object and use $object->name Link to comment Share on other sites More sharing options...
vekia Posted April 30, 2014 Share Posted April 30, 2014 at the moment core doesnt contain any public static function to get category name. you can create it in front controller public static function getCategoryName($id){ $category = new Category ($id,Context::getContext()->language->id); return $category->name; } then you will be able to use {FrontController::getCategoryName(12)} in any .tpl file you want. 4 Link to comment Share on other sites More sharing options...
Sharak Posted April 30, 2014 Author Share Posted April 30, 2014 (edited) Works perfect! Thanks Edited April 30, 2014 by Sharak (see edit history) Link to comment Share on other sites More sharing options...
Sharak Posted April 30, 2014 Author Share Posted April 30, 2014 (edited) Just one more thing. Function getCategoryLink() uses some params: // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); But it seems only ID and rewrite is used here. Is there any way to get meta parameters from it? Also I could add $params['name'] = $category->name; and therefore have one complete function to create full link with link, name, keywords etc. I will figure it out later... Edited June 25, 2014 by Sharak (see edit history) Link to comment Share on other sites More sharing options...
connectcase Posted July 16, 2014 Share Posted July 16, 2014 at the moment core doesnt contain any public static function to get category name. you can create it in front controller public static function getCategoryName($id){ $category = new Category ($id,Context::getContext()->language->id); return $category->name; } then you will be able to use {FrontController::getCategoryName(12)} in any .tpl file you want. So I added this function to /controllers/front/CategoryController.php. Now how do I call it in /themes/default-bootstrap/category.tpl? 1 Link to comment Share on other sites More sharing options...
connectcase Posted July 16, 2014 Share Posted July 16, 2014 Never mind, I figured it out (misread the whole thing).... Link to comment Share on other sites More sharing options...
JoseR Posted November 6, 2014 Share Posted November 6, 2014 Sorry, but I did all the steps but doesn't work (to me). I have this error: Fatal error: Call to undefined method FrontController::getCategoryName() in C:\EasyPHP\data\localweb\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 162 I'm working with PS 1.6.0.9 Thanks! Link to comment Share on other sites More sharing options...
NemoPS Posted November 7, 2014 Share Posted November 7, 2014 Where did you add this exactly? public static function getCategoryName($id){ $category = new Category ($id,Context::getContext()->language->id); return $category->name; } Link to comment Share on other sites More sharing options...
JoseR Posted November 7, 2014 Share Posted November 7, 2014 I was adding it on categorycontroller... Sharak tell me the correct way: \classes\controller\FrontController.php Thanks Nemo1! Link to comment Share on other sites More sharing options...
Denver Prophit Jr. Posted May 26, 2015 Share Posted May 26, 2015 Where did you add this exactly? public static function getCategoryName($id){ $category = new Category ($id,Context::getContext()->language->id); return $category->name; } I would think you should duplicate the controller class into overrides so that updates do not overwrite your custom code? Link to comment Share on other sites More sharing options...
Recommended Posts