Jump to content

Show module only parent category and subcategories (Solved)


JavierP

Recommended Posts

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 by JavierP (see edit history)
Link to comment
Share on other sites

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? 

imagen.thumb.png.38f9447d311f18769895ac3ab9939bb4.png

Link to comment
Share on other sites

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 by JavierP (see edit history)
Link to comment
Share on other sites

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 by JavierP (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...