I
I
Ivseti2022-01-17 09:35:41
opencart
Ivseti, 2022-01-17 09:35:41

How to display the 3rd level of categories in the template on Opencart 2.3?

Good day ! I just can’t figure out how to display the 3rd level in the template header ..

Now my construction displays the main category on the left, the 2nd level and a link to the main category on the right, but you need to display the 3rd level of categories under the 2nd level ... How ?

<div class="catalog-box">
  <div class="table-container">
    <div class="row table-row">
      <div class="col-md-3 col-xs-12 catalog-menu no-float">
        <?php foreach ($categories as $key => $category) { ?>
        <a class="catalog-menu-item" data-id="<?=$key?>" href="<?=$category['href']?>"><?=$category['name']?></a>
        <?php } ?>
      </div>
      <div class="col-md-9 catalog-items no-float hidden-xs">
        <div class="catalog-grid-box">
            <?php foreach ($categories as $key => $category) { ?>
              <?php if ($category['children']) { ?>
              <div class="catalog-item-box" data-id="<?=$key?>" id="main-menu-grid">
                <?php foreach ($category['children'] as $children) { ?>
                <div><a href="<?=$children['href']?>" class="catalog-item"><?=$children['name']?></a></div>
                <?php } ?>
                <div class="all">
                  <a class="catalog-item" href="<?=$category['href']?>">Посмотреть все категории<i class="fa fa-angle-right"></i></a>
                </div>
              </div>
              <?php } ?>
            <?php } ?>
        

      </div>
    </div>
  </div>
</div>
</div>
<div class="catalog-overlay"></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2022-01-17
@Ivseti

Out of the box, Opencart only outputs two levels of categories.

spoiler
$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) {
          $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'])
          );
        }

        // Level 1
        $data['categories'][] = array(
          'name'     => $category['name'],
          'children' => $children_data,
          'column'   => $category['column'] ? $category['column'] : 1,
          'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
        );
      }
    }

Look for the code that will help you get the third level, or add it yourself.
https://opencartforum.com/topic/84245-kategorii-3-... .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question