<Opencart类别模块>显示第二个孩子

时间:2014-11-29 20:49:56

标签: php oop filtering opencart

我一直在努力实现在侧边栏类别模块中显示类别的第二个孩子,就像这样

例如:Toys > boys > RC cars

目前有这个

<ul>
    <?php foreach ($categories as $category) { ?>
    <?php if ($category['category_id'] == $category_id) { ?>
    <li class="cat-active">
        <a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
    <?php } else { ?>
    <li>
        <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
        <?php } ?>
        <?php if ($category['children']) { ?>
        <b class="cc"></b>
        <ul class="col-subcat">
            <?php foreach ($category['children'] as $child) { ?>
            <li>
                <?php if ($child['category_id'] == $child_id) { ?>
                <a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
                <?php } else { ?>
                <a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
                <?php } ?>
            </li>
            <?php } ?>
        </ul>
        <?php } ?>
    </li>
    <?php } ?>
</ul>

仅显示

玩具&gt;男孩

我不确定如何展示第二个孩子(“玩具&gt;男孩&gt; RC汽车”) 提出建议

1 个答案:

答案 0 :(得分:1)

您必须自定义2个文件。

  1. catalog / controller / module / category.php - 39行
  2. 找到“foreach($ children as $ child){”并将下面的代码放在它下面。

    $children_data_2 = array();
    
    $children_2 = $this->model_catalog_category->getCategories($child['category_id']);
    
    foreach ($children_2 as $child_2) {
    	$filter_data = array(
    		'filter_category_id'  => $child_2['category_id'],
    		'filter_sub_category' => true
    	);
    
    	$children_data_2[] = array(
    		'category_id' => $child_2['category_id'],
    		'name'        => $child_2['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'] . '_' . $child_2['category_id'])
    	);
    }

    更改

    $children_data[] = array(
    	'category_id' => $child['category_id'],
    	'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_data[] = array(
    	'category_id' => $child['category_id'],
    	'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_data_2 // insert this line
    );


    1. 目录/视图/主题/ [您的主题目录] /template/module/category.tpl
    2. <ul>
          <?php foreach ($categories as $category) { ?>
          <?php if ($category['category_id'] == $category_id) { ?>
          <li class="cat-active">
              <a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
          <?php } else { ?>
          <li>
              <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
              <?php } ?>
              <?php if ($category['children']) { ?>
              <b class="cc"></b>
              <ul class="col-subcat">
                  <?php foreach ($category['children'] as $child) { ?>
                  <li>
                      <?php if ($child['category_id'] == $child_id) { ?>
                      <a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
                      <?php } else { ?>
                      <a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
                      <?php } ?>
      				<?php if ($child['children']) { ?>
      				<b class="cc"></b>
      				<ul class="col-subcat">
      					<?php foreach ($child['children'] as $child_2) { ?>
      					<li>
      						<?php if ($child_2['category_id'] == $child_id) { ?>
      						<a href="<?php echo $child_2['href']; ?>" class="active"><?php echo $child_2['name']; ?></a>
      						<?php } else { ?>
      						<a href="<?php echo $child_2['href']; ?>"><?php echo $child_2['name']; ?></a>
      						<?php } ?>
      					</li>
      					<?php } ?>
      				</ul>
      				<?php } ?>
                  </li>
                  <?php } ?>
              </ul>
              <?php } ?>
          </li>
          <?php } ?>
      </ul>