dr7tbien Posted February 17, 2023 Share Posted February 17, 2023 (edited) Hello. I'd like to insert a new php function - method called getCategoryName. This is the function: public function getCategoryName( $id_category ){ $idLang = Context::getContext()->language->id; $categoryObject = $this->getCategoryObject($id_category, $idLang); return $categoryObject->name; } It happens that I don't know where to place it properly. I've actually placed it at the end of the classes/Link.php file. I think it is a mistake since it is part of the prestashop core and this method should be overridden. Where should this method be overridden? Edited February 17, 2023 by dr7tbien (see edit history) Link to comment Share on other sites More sharing options...
lordignus Posted February 17, 2023 Share Posted February 17, 2023 (edited) Add the function to /override/classes/Link.php If that file doesn't exist yet, just create it exactly as follows: <?php class Link extends LinkCore { public function getCategoryName( $id_category ){ $idLang = Context::getContext()->language->id; $categoryObject = $this->getCategoryObject($id_category, $idLang); return $categoryObject->name; } } Also, if you need to create the override file, you'll need to regenerate the class index. To do that, just delete /var/cache/prod/class_index.php and /var/cache/dev/class_index.php Edited February 17, 2023 by lordignus Mistake (see edit history) 1 Link to comment Share on other sites More sharing options...
dr7tbien Posted February 17, 2023 Author Share Posted February 17, 2023 2 hours ago, lordignus said: Add the function to /override/classes/Link.php If that file doesn't exist yet, just create it exactly as follows: <?php class Link extends LinkCore { public function getCategoryName( $id_category ){ $idLang = Context::getContext()->language->id; $categoryObject = $this->getCategoryObject($id_category, $idLang); return $categoryObject->name; } } Also, if you need to create the override file, you'll need to regenerate the class index. To do that, just delete /var/cache/prod/class_index.php and /var/cache/dev/class_index.php Many thanks. Really I should start reading something about module development in prestashop. I'm doing it all by coding reverse and reading specific cases like this. Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now