Oskar Livs
Oskar Livs

Reputation: 111

Prestashop - create link to the category that a product belongs to

I'm fairly new at prestashop. On the home page I am using the "Specials Center" module which just displays a list of products that are on sale. I wanted to show which category the product belongs to. I edited SpecialsCenter.tpl and used this code:

<a href="#">Category: {$Specials.category}</a></h2>

This correctly displays the corresponding category name for which the specific product belongs to. See image: Product with category. The only thing I am having trouble with is creating a link to that category. Should be fairly simple but Prestashop forums seem so vacant. All questions. No answers. What is the variable to use to link to the category page?

Thanks for your help.

Having done a little more research...this is where I am now...

<a href="{$link->getCategoryLink({$Specials.id_category}, {$Specials.category})}">Category: {$Specials.category}</a>

So this outputs this link: mysiteurl/0-laptops - this is partly correct, except the category ID is wrong. The id for the category laptops is 4. It should be this: mysiteurl/4-laptops. So the first smarty tag {$Specials.id_category} is incorrect. I need to know how to draw the category ID using a variable of some kind. So it should be something like this:

<a href="{$link->getCategoryLink('category-id', {$Specials.category})}">Category: {$Specials.category}</a>

Thanks again!!! :)

Upvotes: 3

Views: 13474

Answers (1)

Oskar Livs
Oskar Livs

Reputation: 111

SOLUTION FOUND: Ah! Thank you Niclas Larsson - that was helpful! I should have thought about that! :) You were right, it was not pulling "id_category" the correct usage is as follows:

<a href="{$link->getCategoryLink({$Specials.id_category_default} , {$Specials.category})}">{$Specials.category}</a>

Upvotes: 7

Related Questions