This is the code for header.php:
Code: Select all
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
if ($category['image']) {
$image = $this->model_tool_image->resize($category['image'], 30, 30);
} else {
$image = $this->model_tool_image->resize('no_image.png', 30, 30);
}
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array();
$filter_data2 = array();
$children_data2 = array();
$children2 = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($children2 as $child2) {
$filter_data2 = array(
'filter_category_id' => $child2['category_id'],
'filter_sub_category' => true
);
$children_data2[] = array(
'name' => $child2['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data2) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $child2['category_id']),
);
}
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$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']),
'children' => $children_data2,
);
}
$data['categories'][] = array(
'thumb' => $image,
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
Code: Select all
{% if categories %}
{% for category in categories %}
{% if category.children %}
<li class="menu-link">
<a href="{{ category['href'] }}" data-toggle="dropdown" class="dropdown-toggle"><img src="{{ category['thumb'] }}" class="imgmenucat" loading="lazy" alt="{{ category['name'] }}" title="{{ category['name'] }}" />{{ category['name'] }}</a><span class="mobile-plus"><i class="fas fa-chevron-down"></i></span>
{% for children in category.children|batch(category.children|length / category.column|round(1, 'ceil')) %}
<ul class="dropdown-menu sub-block">
<li><a href="{{ category['href'] }}" class="see-all">{{ text_all }} {{ category['name'] }}</a></li>
<li role="separator" class="divider"></li>
{% for child in children %}
{% if child.children %}
<li class="submenu-link">
<a href="{{ child['href'] }}" data-toggle="dropdown" class="dropdown-toggle">{{ child['name'] }}</a><span class="mobile-plus"><i class="fas fa-chevron-down"></i></span>
<ul class="dropdown-menu sub-block">
<li><a href="{{ child['href'] }}" class="see-all">{{ text_all }} {{ child['name'] }}</a></li>
<li role="separator" class="divider"></li>
{% for children in child.children %}
<li><a href="{{ child['href'] }}">{{ child['name'] }}</a></li>
{% endfor %}
</ul>
</li>
{% else %}
<li><a href="{{ child['href'] }}">{{ child['name'] }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
</li>
{% else %}
<li class="menu-link"><a href="{{ category['href'] }}"><img src="{{ category['thumb'] }}" class="imgmenucat" loading="lazy" alt="{{ category['name'] }}" title="{{ category['name'] }}"/>{{ category['name'] }}</a></li>
{% endif %}
{% endfor %}
{% endif %}
Thanks in advance..