Jump to content

[RESOLVED] Changes to categories


menegonfabio
 Share

Recommended Posts

Posted (edited)

Hello everybody!
I am new to Prestashop, and I must admit that I know very little about PHP.
I was asked to add a table on a product page in the subcategory. The categories are divided as follows: Home / Products / Boxes / Boxes model.
Now, I was able to add the table in the desired position by working in the Category.tpl file, but the problem that I encounter, and that I cannot solve, is that in addition to putting the table in the last subcategories, it also displays it in the sub-categories previous categories.
My request is: could someone help me in making sure that the table is displayed only in the last subcategory ???
I assume I have to do a condition with a foreach in the Category.php file, but besides not understanding how to do it, I'm not sure it's the right solution.
Thanks in advance for those who will answer.

 

PrestaShop Version: 1.7.7.5

PHP Version: 7.4.21

Edited by menegonfabio (see edit history)

Share this post


Link to post
Share on other sites

Sure!
This is the final result (one of the last sub-categories where I have to view the table). The others you see in the path above do not have to show the table.

10 minutes ago, SmartDataSoft said:

Hai qualche immagine di esempio come ti piace fare. Ci sarà chiaro. Per dare una soluzione migliore

 

Grazie

 

Immagine 2021-07-20 170500.png

Share this post


Link to post
Share on other sites

@menegonfabio


This can be done with a strict way. you need to select which category depth you will show the content. Without level_depth  this is not possible to do.

If you print  {$category|print_r} in side  1.7.7.5\themes\classic\templates\catalog\_partials\category-header.tpl

then it will print 


Array ( [nleft] => 4 [nright] => 5 [level_depth] => 3 [id_parent] => 3 [id_shop_default] => 1 [is_root_category] => 0 [position] => 0 [date_add] => 2021-07-20 17:07:35 [date_upd] => 2021-07-20 17:10:30 [name] => two [link_rewrite] => two [description] =>...

after that you can use this code to show your table

 {if $category.level_depth>=3}
this is table
 {/if}

I think you are able to understand my solution and able to solve

 

Thank you

  • Thanks 1

Share this post


Link to post
Share on other sites

  • menegonfabio changed the title to [RESOLVED] Changes to categories

@SmartDataSoft

Is it possible to do the same but with a cycle that counts all the sub-categories and adds the table to the last sub-category?

Because it may happen that categories are added in the future and I would like to avoid changing the .tpl file every time.

Thank you

Share this post


Link to post
Share on other sites

@menegonfabio

The things is that in category page PrestaShop do not sent it's child category list or other information other than depth. 

Their is two way we can do

1. add a custom hook where we send information of this category child or other then we will show the table

2. add a filed in admin category depending that value we will show the table

 

thank you

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More