i'm trying to display the subcategories related to parent only what i have achieved sofar is
here is the category.php controller
Code: Select all
$categories = $this->model_catalog_category->getCategories(0);
$category_info = $this->model_catalog_category->getCategory($data['category_id']);
$data['parent_name'] = $category_info['name'];
$data['parent_id'] = $category_info['parent_id'];
$data['category_id'] = $category_info['category_id'];
$data['category_name'] = $category_info['name'];
$data['parent_href'] = $this->url->link('product/category', 'path=' . $this->request->get['path']);
$data['child_href_parent'] = $this->url->link('product/category', 'path=' . $category_info['parent_id']);
var_dump($category_info['parent_id']);
var_dump($category_info['category_id']);
var_dump($category_info['name']);
foreach ($categories as $category) {
$filter_data = array(
'filter_category_id' => $category['category_id'],
'filter_sub_category' => true
);
$data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'parent_id' => $category['parent_id'],
//'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}//foreach
$children_data = array();
$children = $this->model_catalog_category->getCategories($data['category_id']);
foreach($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$data['children'][] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'parent_id' => $child['parent_id'],
'href' => $this->url->link('product/category', 'path=' . $child['category_id'])
);
}
[code]
and the category.tpl
[code]<div class="list-group">
<?php foreach ($categories as $category) { ?>
<?php } ?>
<?php if (!empty($children)) { ?>
<a href="<?php echo $parent_href; ?>" class="list-group-item active"><i class="fa fa-arrow-circle-o-right" aria-hidden="true"></i> <?php echo $parent_name; ?></a>
<?php foreach ($children as $child) { ?>
<?php if ($category_id == $child['parent_id']) { ?>
<a href="<?php echo $child['href']; ?>" class="list-group-item active"> - <?php echo $child['name']; ?></a>
<?php } ?>
<?php } ?>
<?php } else { ?>
<?php } ?>
</div>
[code]
it displays perfectly as expected however if i reach the last category i get no subcategory because it doesn't have childs, hat i need is to stop or display the last level i'm in check the images
[attachment=]https://forum.opencart.com/download/file.php?mode=view&id=31558[/attachment]
now if i click on any subcategory it returns empty i need to stop the loop till this level or break it if empty and display same results