1 回答
TA贡献1780条经验 获得超5个赞
您有非标准模板。但这会起作用。 目录/控制器/扩展/模块/category.php
<?php
class ControllerExtensionModuleCategory extends Controller {
public function index() {
$this->load->language('extension/module/category');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$data['category_id'] = $parts[0];
} else {
$data['category_id'] = 0;
}
if (isset($parts[1])) {
$data['child_id'] = $parts[1];
} else {
$data['child_id'] = 0;
}
if (isset($parts[2])) {
$data['grand_child_id'] = $parts[2];
} else {
$data['grand_child_id'] = 0;
}
if (isset($parts[3])) {
$data['grand_child_2_id'] = $parts[3];
} else {
$data['grand_child_2_id'] = 0;
}
$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']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
// Level 3
$children_data_3 = array();
$children_3 = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($children_3 as $child_3) {
// Level 4
$children_data_4 = array();
$children_4 = $this->model_catalog_category->getCategories($child_3['category_id']);
foreach ($children_4 as $child_4) {
$filter_data_4 = array(
'filter_category_id' => $child_4['category_id'],
'filter_sub_category' => true
);
$children_data_4[] = array(
'name' => $child_4['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data_4) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $child_3['category_id'] . '_' . $child_4['category_id'])
);
}
//end of level 4
$filter_data_3 = array(
'filter_category_id' => $child_3['category_id'],
'filter_sub_category' => true
);
$children_data_3[] = array(
'name' => $child_3['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data_3) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $child['category_id'] . '_' . $child_3['category_id']),
'grand_childs_2' => $children_data_4 //for level 4
);
}
//end of level 3
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'thumb_menus' => HTTP_SERVER . 'image/' .$child['image'],
'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']),
'grand_childs' => $children_data_3//for level 3
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'thumb_menu' => HTTP_SERVER . 'image/' . $category['image'],
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
return $this->load->view('extension/module/category', $data);
}
}
目录/视图/主题/默认/模板/扩展/模块/category.twig
<div class="hidden-xs">
{% if categories %}
<div class="cateti">
<h3><i class="fa fa-list"></i>category</h3>
</div>
<div class="cate-menu ">
<nav id="menu" class="navbar">
<div class="navbar-header"><span id="category" class="visible-xs">{{ text_category }}</span>
<button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav">
{% for category in categories %}
{% if category.children %}
<li class="dropdown"><a href="{{ category.href }}" class="dropdown-toggle header-menu" data-toggle="dropdown">{{ category.name }}<i class="fa fa-angle-down enangle"></i></a>
<div class="dropdown-menu">
<div class="dropdown-inner">
{% for children in category.children|batch(category.children|length / category.column|round(1, 'ceil')) %}
<ul class="list-unstyled">
{% for child in children %}
{% if child.grand_childs %}
<li class="dropdownj02"> <a href="{{ child.href }}" class="dropdown-toggle header-menu" data-toggle="dropdown"> {{ child.name }}<i class="fa fa-angle-down enangle"></i> </a>
<div class="dropdown-menuj02">
<div class="dropdown-inner">
<ul class="list-unstyled grand-child">
{% for grand_child in child.grand_childs %}
{% if grand_child.grand_childs_2 %}
<li class="dropdownj03"><a href="{{ grand_child.href }}" class="dropdown-toggle header-menu" data-toggle="dropdown">{{ grand_child.name }}<i class="fa fa-angle-down enangle"></i> </a>
<div class="dropdown-menuj03">
<div class="dropdown-inner">
<ul class="list-unstyled grand-child_2">
{% for grand_child_2 in grand_child.grand_childs_2 %}
<li><a href="{{ grand_child_2.href }}"> {{grand_child_2.name}} </a> </li>
{% endfor %}
</ul>
</div>
</div>
</li>
{% else %}
<li><a href="{{ grand_child.href }}">{{grand_child.name}}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</li>
{% else %}
<li><a href="{{ child.href }}"> {{ child.name }} </a></li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}</div>
</div>
</li>
{% else %}
<li><a href="{{ category.href }}">{{ category.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
</nav>
</div>
{% endif %}
</div>
<script type="text/javascript">
function headermenu() {
if (jQuery(window).width() < 992)
{
jQuery('ul.nav li.dropdown a.header-menu').attr("data-toggle","dropdown");
}
else
{
jQuery('ul.nav li.dropdown a.header-menu').attr("data-toggle","");
}
}
$(document).ready(function(){headermenu();});
jQuery(window).resize(function() {headermenu();});
jQuery(window).scroll(function() {headermenu();});
</script>
- 1 回答
- 0 关注
- 80 浏览
添加回答
举报