Reputation: 23
Okay, I've been asked to repost this as a moderator deemed it to be a 'new' question to this thread: opencart - get parent category name/id on a sub-category page
I believe it to be a valid question related to that title so have posted it here in compliance. Any help would be very much appreciated:
Being a newbie to this concept I'm struggling to interpret the logic within the original thread [above] when applying it to my particular scenario; I'm trying to display the currently displayed category's parent category name. In category.php I've included the line $categories = explode('_', $this->request->get['path']);
but am having difficulty in displaying the parent category name. I'm unclear as to the correct variable name to use in category.tpl to display this. Could someone please advise? Thanks.
Upvotes: 2
Views: 9308
Reputation: 890
In page catalog/controller/product/catalog.php
find the line
if ($category_info) {
Then add below code inside above line
$data['parent_cat_info'] = array();
if($category_info['parent_id'] != 0){
$data['parent_cat_info'] = $this->model_catalog_category->getCategory($category_info['parent_id']);
}
and in page catalog/view/theme/yourtheme/template/product/category.tpl
add where you like to diaplay
<?php //print_r($parent_cat_info);
if($parent_cat_info){
echo $parent_id=$parent_cat_info['category_id'];
echo $parent_name=$parent_cat_info['name'];
}
?>
Upvotes: 1
Reputation: 1
There is a way easier way to get them.
If you install the export/import tool that exports the DB into an xls.
It has the cateogory id and name associated on the category tab inside the xls.
http://www.opencart.com/index.php?route=extension/extension/info&extension_id=17
Its very simple and elegant, best method is to simply not convolute. :)
Hope this helps everyone.
Cheers
NickTailor nicktailor.com
Upvotes: -1
Reputation: 1204
Find (catalog/controller/product/category.php) around line 95
if ($category_info) {
Add inside
if($category_info['parent_id'] != 0){
$this->data['parent_cat_info'] = $this->model_catalog_category->getCategory($category_info['parent_id']);
}
now in template file (/catalog/view/theme/default/template/product/category.tpl) you can access the properties of array $parent_cat_info
e.g for category name echo $parent_cat_info['name']
Upvotes: 3