Jump to content

Recommended Posts

Hello,

If a product belongs to several categories, could you tell me how to display these category names in a product page (Prestashop 1.7.6.8)
(that the name of the category of the last level) in the form of "link"
And if it is possible exclude this display on 1 categories.

...to display in my product pages which categories this product belongs to.

To have a final result as follows in front affice :
This product belongs to the following categories :
xxxxxxx, xxxxxxxx, xxxxxxxxxx, xxxxxxxxxx, xxxxxxxxx,

Thank you for your help.

Link to comment
Share on other sites

i tried this :

<ul class="productcats">

 {foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat}

    <li><a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a></li>

{/foreach}

</ul>

In this example i have the link for my categorie but it show full category path

if possible to show only the last level

Thank you

Link to comment
Share on other sites

à l’instant, Guest a dit :

Je réponds dans la langue dans laquelle le sujet a été fondé.
Ce n'est pas un problème pour moi d'utiliser un traducteur.
Signalez le sujet au modérateur et demandez-lui de passer sur le forum anglais 😉
Merci

Le signalement fut fait depuis plus de 12 h et vous même auriez pu faire ce signalement puisque vous maitrisez très bien le forum.

Les sections existe pour une bonne raison alors merci de respecter la structure du forum pour lui conserver une certaine cohérence.

Link to comment
Share on other sites

Bonjour Tengler,
Merci pour votre aide.
Je vais essayer demain et je donnerais des nouvelles.
Apparement j'ai poster un topic dans la mauvaise rubrique concernant la langue, je ne savais pas qu'il y'avait 
Merci encore une fois.

Hello Tengler,
Thanks for your help.
I will try tomorrow and give updates. Apparently I posted a topic in the wrong section concerning the language,
Thanks again.

Link to comment
Share on other sites

Hi,

Only this one work perfect for me,

<ul class="productcats">
 {foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat}
{if $cat.id_category!=2}
    <li><a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a></li>
{/if}
{/foreach}
</ul>

But it show all category path, I need to know if I can do some changes to display only the last level
Thank you.

Link to comment
Share on other sites

Hi Tengler,
After doing this manipulation I have no access to my website, I restored my backup 😓
As I told you in my previous message, it's the only code that works (it's not yours) but it show all category path, I need to know if I can do some changes to display only the last level

<ul class="productcats">
 {foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat}
{if $cat.id_category!=2}
    <li><a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a></li>
{/if}
{/foreach}
</ul>

Thank you.

Link to comment
Share on other sites

4 hours ago, Norben said:

Hi Tengler,
After doing this manipulation I have no access to my website, I restored my backup 😓
As I told you in my previous message, it's the only code that works (it's not yours) but it show all category path, I need to know if I can do some changes to display only the last level


<ul class="productcats">
 {foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat}
{if $cat.id_category!=2}
    <li><a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a></li>
{/if}
{/foreach}
</ul>

Thank you.

Hi,

Not sure what exactly you want but You might want try to use smarty last iteration. So instead of

{if $cat.id_category!=2}

Try

{if $cat.last}

It should display only last item from foreach.

Thanks

Edited by Verlonimo (see edit history)
Link to comment
Share on other sites

Hi Verlimino,

if a product is associated with several categories I want to display in the product page these category names to which this product belongs, the code I posted works but it shows me the whole tree of categories, I want to display only the the list of last levels category 

Link to comment
Share on other sites

  • 2 weeks later...
  • 9 months later...

This works in prestashop 1.7.7.5 in product tpl

<ul class="productcats">
  {foreach from=Product::getProductCategories($product.id) item=cat}
	{if $cat > 2}
		{assign var='current_cat' value=Category::getCategoryInformations(array($cat))}
		<li><a href="{$link->getCategoryLink({$cat})}" title="{$current_cat[{$cat}]['name']}">{$current_cat[{$cat}]['name']}</a></li>
	{/if}
  {/foreach}
</ul>

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
On 9/20/2021 at 12:57 PM, hhcj said:

This works in prestashop 1.7.7.5 in product tpl

<ul class="productcats">
  {foreach from=Product::getProductCategories($product.id) item=cat}
	{if $cat > 2}
		{assign var='current_cat' value=Category::getCategoryInformations(array($cat))}
		<li><a href="{$link->getCategoryLink({$cat})}" title="{$current_cat[{$cat}]['name']}">{$current_cat[{$cat}]['name']}</a></li>
	{/if}
  {/foreach}
</ul>

 

This has worked for me:

It's Category::getCategoryInformation(array($cat))} not "getCategoryInformations(...)"

 
<ul class="productcats">
{foreach from=Product::getProductCategories($product.id) item=cat}
{if $cat > 2}
{assign var='current_cat' value=Category::getCategoryInformation(array($cat))}
<li><a href="{$link->getCategoryLink({$cat})}" title="{$current_cat[{$cat}]['name']}">{$current_cat[{$cat}]['name']}</a></li>
{/if}
{/foreach}
</ul>

 

Edited by Abu Joury (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...