Opencart - How do I get a category name on a product details page?

I want to show the category name on the product details page. I could do this by showing the last palette (which would be a category), but if I do, it will not appear if I get access to the product from the "special" page (Since it does not display categories in breadcrumb - simply "Home> Product2").

How do I get the category identifier so that I can then extract the title from it?

Thanks!

+4
source share
1 answer

I found a solution:

In / catalog / controller / product / product.php

somewhere after line 129 add:

$categories = $this->model_catalog_product->getCategories($product_id); if ($categories) $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']); $this->data['category_title'] = $categories_info['name']; 

This will lead to the title of the first product category (since the product can be in more than one category).

After that, in the product.tpl file echo $category_title;

+7
source

Source: https://habr.com/ru/post/1402552/


All Articles