JavierP Posted December 15, 2020 Share Posted December 15, 2020 (edited) Hello friends, I need to know how I can show a filter module, only in the parent category and subcategories that I want using the IDs, for example. Using the $currentCategory = Tools :: getValue ('id_category'); if ($ currentCategory! = 2) return; It only works on the ID that you put "2". That is, it is displayed in the "home" for example but not in the subcategories. I hope your help, I have not touched internal code for a long time;) thanks Edited December 21, 2020 by JavierP (see edit history) Link to comment Share on other sites More sharing options...
JavierP Posted December 20, 2020 Author Share Posted December 20, 2020 hello no one can enlighten me on how to do it ... thanks Link to comment Share on other sites More sharing options...
Guest Posted December 20, 2020 Share Posted December 20, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
JavierP Posted December 20, 2020 Author Share Posted December 20, 2020 hace 4 horas, 4you.software dijo: Wondering why no one answers? You do not write the version of PrestaShop and also which module must be modified. Each module that displays content also has hooks in which it displays content. So you have to find the hook in the module and set the condition. This is universal advice for your question. Thanks friend for your answer, I know. Sorry, I have not put a version because I have already put the "code" that I am using so that it only appears in the Category ID that I put ..... I am simply asking how this code can be modified so that it can also work in the subcategories. But if you need to know that, I make it easy for you. PS 1.7.6.9 and Module Carpartsfilter Needs more information? Link to comment Share on other sites More sharing options...
Guest Posted December 20, 2020 Share Posted December 20, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
JavierP Posted December 20, 2020 Author Share Posted December 20, 2020 (edited) hace 22 horas, 4you.software dijo: and you know you didn't display the most important part of the code? It is necessary to show the whole code of the hook, especially the return part. You can't hide important information for advice. If you put an image instead of a text code, no one here will write the entire code and copy the code from the image. Your mistake. Sorry, unfortunately you won't get an answer from me. I am also not a free private counseling center and do not write me any private messages anymore. Answer ? I can write the same as yours. You have to write if .... .... return .... ... ; Fill in the code according to your code image. Sorry. Edited December 21, 2020 by JavierP (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted December 21, 2020 Share Posted December 21, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted December 21, 2020 Share Posted December 21, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
JavierP Posted December 21, 2020 Author Share Posted December 21, 2020 (edited) hace 2 horas, 4you.software dijo: Hi. You can add two conditions to the beginning of the code. If you do not want to display the module in certain categories, you will create an array of categories, if you do not want to display the module on certain pages, you will create an array of pages. For example, I don't want to display the module in categories 2 and 6. Enter this part of the code: class PartsFilter extends Module { private $disabled_categories = array('2', '6'); public function __construct() { ..... For example, I don't want the module to appear on the index pages and on the product detail page. Enter this part of the code: class PartsFilter extends Module { private $disabled_pages = array('index', 'product'); public function __construct() { ..... For both options, the code will be: class PartsFilter extends Module { private $disabled_categories = array('2', '6'); private $disabled_pages = array('index', 'product'); public function __construct() { ..... And now the most important part. You will find a hook and add a condition until the end of the function. For example, for hookDisplayTop, the code snippet will be: public function hookDisplayTop($params) { ... ... $page_name = Dispatcher::getInstance()->getController(); if (!in_array($page_name, $this->disabled_pages) && !in_array(Tools::getValue('id_category'), $this->disabled_categories)) { return $this->display(__FILE__, 'views/templates/front/filterbox_top.tpl'); } } For example, for hookDisplayLeftColumn, the code snippet will be: public function hookDisplayLeftColumn($params) { ... ... $page_name = Dispatcher::getInstance()->getController(); if (!in_array($page_name, $this->disabled_pages) && !in_array(Tools::getValue('id_category'), $this->disabled_categories)) { return $this->display(__FILE__, 'views/templates/front/filterbox.tpl'); } } etc. Thank you for your quick response. I do not know, if I am making a mistake when implementing the code, but it does not work for me, it is shown in all categories. I am attaching the code, so that you can verify if I am including it correctly.😓 Edited December 21, 2020 by JavierP (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted December 21, 2020 Share Posted December 21, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted December 21, 2020 Share Posted December 21, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
JavierP Posted December 21, 2020 Author Share Posted December 21, 2020 ok understood, thanks for your clarification. But I add the IDs of the categories where I don't want it to be shown ... but it ignores, it continues to show the module Link to comment Share on other sites More sharing options...
JavierP Posted December 21, 2020 Author Share Posted December 21, 2020 ok now work @4you.software but, can't you put the rule the other way around, that is, put only in the categories that I want the module to show? Because in the subcategories of the other parent categories, it continues to show if I don't add all the ids. But there are many ids. Link to comment Share on other sites More sharing options...
Guest Posted December 21, 2020 Share Posted December 21, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
JavierP Posted December 21, 2020 Author Share Posted December 21, 2020 thanks @4you.software solved 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