Latest Articles
So far this was never an issue, there were problems with uploading modules via the installer because of the ftp connection but you could allways install ocmods without any issue. However, some .. Read More
People had this issue so many times I thought I would write a bit about it. The  types of issues with opencart's 2.x modification system that I identified so far are: 1. Old Vqmod .. Read More
This small tutorial will show you how to manually add custom links to the default top menu in opencart. If you dont want to go trough all the hustle and would like to be able to completly customize.. Read More
To enable seo urls in opencart navigate in admin to system > settings , edit the store and on the server tab of the store settings you will find "Use SEO urls", set it to yes. So far e.. Read More
All Articles

Display category on product page opencart 1.5x

If you want to display the categories a product belongs to on the product page (like the manufacturer is now), here is how you proceed:

In catalog/controller/product/product.php look for the line:

$this->load->model('catalog/product');


below it add:

//product category

$this->load->model('catalog/category');

$this->data['catprod'] = array();

$product_category = $this->model_catalog_product->getCategories($product_id);

foreach ($product_category as $prodcat) {

$category_info = $this->model_catalog_category->getCategory($prodcat['category_id']);

if ($category_info) {

$this->data['catprod'][] = array(
'name' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $category_info['category_id'])
);
}
}
//end of product category



In catalog/view/theme/yourtheme/template/product/product.tpl find the line:

<?php if ($manufacturer) { ?>



And above it add:

<span>Categories: </span><?php foreach ($catprod as $catp) { ?> <a href="/<?php echo $catp['href']; ?>"><?php echo $catp['name']; ?></a> |<?php } ?><br />

 

That is all.

Posted by Flo

Related Articles

Even if this issue has been fixed for a while in opencart, some people stil seem to have problems with disabling the product count next to the category name in the opencart left category menu, on the top menu's dropdown and on the subcategories from within a category's page. In the most recent versions of opencart there is one simple setting to disable the product count in all those instaces, the setting can be found in admin > system > settings. Edit the main store, go to the option tab and the first setting below the products heading is category product count, set it to ..
2 comments on this article - view comments

18 Comments To "Display category on product page opencart 1.5x"

Bob Connolly On 06 Dec 2014
Fantastic, just what I was looking for! Thank you! Reply to this comment
Davide On 30 Nov 2013
Hi! I use this code on opencart 1.5.6 but I can't get it working! Can you help me to solve this please? Reply to this comment
ujita On 20 Sep 2013
hello.. i am totally new to opencart.... so will any one tell me that how to add a product into a newly created category??? Thank you..... Reply to this comment
deadrockerrr On 24 Jul 2013
Thnks a lot !!!!!!!!!!!!! awsm awsm code save my life as i am very beginner to opencart cms. I would like to know that how can i add the category name and total number of products count in that category at cart page...plzz give some idea...help me.. Reply to this comment
Aenur rohman indonesia On 28 May 2013
Good Job Mr.. Thank U a lot... Reply to this comment
Gil On 13 Apr 2013
Hello Flo, If I may ask, how would you show specific categories/subcategories, each on its own line ? Here is what I want to achieve (to be shown under the Brand/Manufacturer line in the product page). Type: Desktop OS: Windows 7 (With links to "Desktop" & "Windows 7", of course compatible with breadcrumbs - same behaviour as the existing "Brand", in fact, which is a category as well) "Type" & "OS" being specific categories and "Desktop" & "Windows 7" being related subcategories. Thanks for you time! Gil Reply to this comment
mateuszm On 21 Sep 2012
THANK YOU VERY MUCH! You helped me a lot. Reply to this comment
marcobo On 10 Sep 2012
FANTASTIC!!!!!!!!!!!!!! tanks Reply to this comment
capdase On 24 Jun 2012
In my site I have same product linked to multiple sub category. How do I give preference on displaying that sub category to a product. http://www.kewl.in Reply to this comment
Anyeos On 17 Jun 2012
Same here, the address is duplicated (double root domain). Reply to this comment

Write a comment

Your Name:


Enter the code in the box below:

Your Comment:
Note: HTML is not translated!