Reputation: 5309
My category structure is:
Electronics
-TV
--LG
--ONIDA
-Fridge
--Whirlpool
--Videocon
-Music Player
--Sony
--LG
Furniture
-Wooden
--Chair
--Bed
-Metal
--Chair
Here my main categories are Electronics, Furniture
; Subcategories are TV, Fridge etc
and sub-subcategories are LG, Onida etc
. That is I have 3 level categories.
I have to display these in main navigation menu in Opencart
.
But in Opencart
main category and sub categories
are only displayed. Third level category
are not displayed.
So how I display the third level category. Here I am attaching a image, that tell my requirement more clear.
My Opencart version is 2.0.3.1
EDIT
Here is the code for displaying the category menu.
catalog\view\theme\default\template\common\header.tpl
<ul class="nav navbar-nav">
<?php foreach ($categories as $category) { ?>
<?php if ($category['children']) { ?>
<li class="dropdown"><a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?></a>
<div class="dropdown-menu">
<div class="dropdown-inner">
<?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
<ul class="list-unstyled">
<?php foreach ($children as $child) { ?>
<li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<a href="<?php echo $category['href']; ?>" class="see-all"><?php echo $text_all; ?> <?php echo $category['name']; ?></a> </div>
</li>
<?php } else { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
Upvotes: 1
Views: 2698
Reputation:
Note : It's not recommended to make the direct changes in the core files. You can make the vqmod for the same changes. changes given here are tested in the default template, it might be different in other custom theme.
(1) Open file catalog/controller/common/header.php and search for
$children_data = array();
and write below code after it
$children_lv3_data = array();
2) In same file Replace
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
with below code
$children_lv3 = $this->model_catalog_category->getCategories($child['category_id']);
if($children_lv3)
{
foreach ($children_lv3 as $child_lv3)
{
$filter_data_lv3 = array(
'filter_category_id' => $child_lv3['category_id'],
'filter_sub_category' => true
);
$children_lv3_data[] = array(
'category_id' => $child_lv3['category_id'],
'name' => $child_lv3['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data_lv3) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $child_lv3['category_id'])
);
}
$children_data[] = array(
'children_lv3' => $children_lv3_data,
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
else
{
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
3) Open file catalog/view/theme/default/template/common/header.tpl and search for
<li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
and put below code after it
<?php if(isset($child['children_lv3']) && count($child['children_lv3'])>0){ ?>
<ul>
<?php foreach ($child['children_lv3'] as $child_lv3) { ?>
<li><a href="<?php echo $child_lv3['href']; ?>"><?php echo $child_lv3['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
Upvotes: 1