MKZ Industries Posted January 29 Share Posted January 29 Hi all, I would like to add an external link to a subcategory so that when a customer clicks on that subcategory, he is redirected to another external website. Both in the main manu and in the category tree. Let's imagine that I have the following categories and subcategories: Laptops Mobile phones - Motorola - Samsung The idea is that if someone clicks on ‘Motorola’, they will be taken to www.motorola.com. I have managed to do this for the top menu modifying as follows the "generateCategoriesmenu" function in "modules\ps_mainmenu\ps_mainmenu.php", but I haven't been able to do it for the category tree on the left column. foreach ($categories as $key => $category) { $node = $this->makeNode([]); if ($category['level_depth'] > 1) { $cat = new Category($category['id_category']); if ((int)$cat ->id_category == 12) $link = "https://www.motorola.com"; else $link = $cat->getLink(); // Check if customer is set and check access if (Validate::isLoadedObject($this->context->customer) && !$cat->checkAccess($this->context->customer->id)) { continue; } } else { $link = $this->context->link->getPageLink('index'); } How could I do this? Any ideas with a different approach? Thank you very much for your help and best regards Link to comment Share on other sites More sharing options...
MKZ Industries Posted Wednesday at 11:38 AM Author Share Posted Wednesday at 11:38 AM Hello again, and apologies for posting twice. I've kept trying things, but I'm going to give up... Is it that difficult? Link to comment Share on other sites More sharing options...
Nickz Posted Wednesday at 02:14 PM Share Posted Wednesday at 02:14 PM if you stuff too many products into a shop you might confuse buyers, all depends on if the categories are easily found on the internet. 3 Clicks to pay for a product is ideal. Link to comment Share on other sites More sharing options...
4presta Posted Wednesday at 02:49 PM Share Posted Wednesday at 02:49 PM On 1/29/2026 at 2:45 PM, MKZ Industries said: The idea is that if someone clicks on ‘Motorola’, they will be taken to www.motorola.com. I have managed to do this for the top menu modifying as follows the "generateCategoriesmenu" function in "modules\ps_mainmenu\ps_mainmenu.php", but I haven't been able to do it for the category tree on the left column. Hi. There is a module ps_categorytree on the left menu display. You would also have to edit ps_categorytree.php specifically the formatCategory function Link to comment Share on other sites More sharing options...
MKZ Industries Posted 16 hours ago Author Share Posted 16 hours ago (edited) 17 hours ago, 4presta said: Hi. There is a module ps_categorytree on the left menu display. You would also have to edit ps_categorytree.php specifically the formatCategory function Yes, I have been playing around with that file and function, but I must be doing something wrong. This is the original code of that function in PS 8.2: private function formatCategory($rawCategory, $idsOfCategoriesInPath): array { $children = []; if (!empty($rawCategory['children'])) { foreach ($rawCategory['children'] as $k => $v) { $children[$k] = $this->formatCategory($v, $idsOfCategoriesInPath); } } return [ 'id' => $rawCategory['id_category'], 'link' => $this->context->link->getCategoryLink($rawCategory['id_category'], $rawCategory['link_rewrite']), 'name' => $rawCategory['name'], 'desc' => $rawCategory['description'], 'children' => $children, 'in_path' => in_array($rawCategory['id_category'], $idsOfCategoriesInPath), ]; } The idea is the same as with the main menu: add a condition so that when the category ID is 12, the link is ‘www.motorola.com’. I'm not an expert in PHP code and I may not be using the correct syntax, but it should be something like this: private function formatCategory($rawCategory, $idsOfCategoriesInPath): array { $children = []; if (!empty($rawCategory['children'])) { foreach ($rawCategory['children'] as $k => $v) { $children[$k] = $this->formatCategory($v, $idsOfCategoriesInPath); } } return [ 'id' => $rawCategory['id_category'], if($rawCategory['id_category'] == 12){ 'link' = "https://www.motorola.com"; } else { 'link' => $this->context->link->getCategoryLink($rawCategory['id_category'], $rawCategory['link_rewrite']); }, 'name' => $rawCategory['name'], 'desc' => $rawCategory['description'], 'children' => $children, 'in_path' => in_array($rawCategory['id_category'], $idsOfCategoriesInPath), ]; } Edited 16 hours ago by MKZ Industries (see edit history) 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