@idpabloo

Как вывести подкатегории на Home opencart 3x?

Как вывести подкатегории на Home opencart 3x?
<div class="list-group">
        {% for category in categories %}
        {% if category.category_id == category_id %} 
        <a href="{{ category.href }}" class="list-group-item active">{{ category.name }}</a> 
        {% if category.children %}
        {% for child in category.children %}
        {% if child.category_id == child_id %}
        <a href="{{ child.href }}" class="list-group-item active">&nbsp;&nbsp;&nbsp;- {{ child.name }}</a> 
        {% else %} 
        <a href="{{ child.href }}" class="list-group-item">&nbsp;&nbsp;&nbsp;- {{ child.name }}</a>
        {% endif %}
        {% endfor %}
        {% endif %}
        {% else %} <a href="{{ category.href }}" class="list-group-item">{{ category.name }}</a>
        {% endif %}
        {% endfor %}
      </div>

Это выводит только категории. Что переделать куда копать?
  • Вопрос задан
  • 1403 просмотра
Пригласить эксперта
Ответы на вопрос 2
lazuren
@lazuren
В контроллере предусмотрено только 2 уровня вложенности, вот должно быть похожий вопрос.
Ответ написан
Комментировать
@idpabloo Автор вопроса
Вопрос решен
создан дополнительный модуль в controller прописал
<?php
class ControllerExtensionModuleCategoryWall extends Controller {

    public function index() {
        $this->load->language('extension/module/category_wall');

        $data['heading_title'] = $this->language->get('heading_title');

        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;
        }

        $this->load->model('catalog/category');

        $this->load->model('catalog/product');

        $data['categories'] = array();

        $data['categories'] = array();

        $categories = $this->model_catalog_category->getCategories(0);

        $this->load->model('tool/image');

        foreach ($categories as $category) {
            $children_data = array();
            if ($category['top']) {
                $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);
                    if ($child['image']) {
                        $image = $this->model_tool_image->resize($child['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
                     } else {
                        $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
                    }
                    $children_data[] = array(
                        'category_id' => $child['category_id'],
                        'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
                        'image' => $image,
                        'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
                    );
                }    
            if ($category['image']) {
                $image = $this->model_tool_image->resize($category['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
            } else {
                $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
            }

            $data['categories'][] = array(
                'category_id' => $category['category_id'],
                'description' => $category['description'],
                'name' => $category['name'],
                'children'    => $children_data,
                'image' => $image,
                'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
                );
            }
        }
		return $this->load->view('extension/module/category_wall', $data);
		
        
    }
}


в twig прописал
<section class="category_table">
  <div class="container">
  {% for category in categories %}
     {% if category.category_id == 62 %}  
    <h3>{{ category.name }}</h3>
    <div class="row">
         
 
              {% if category.children %}
               {% for child in category.children  %}
                {% if child.category_id == child_id %}
                  <div class="col-sm-12 col-12">
                <div class="category_child">
                <a href="{{ child.href }}"><img src="{{ child.image }}" alt="{{ child.name }}" title="{{ child.name }}" class="img-responsive" /></a>
                <div class="child_name"><a href="{{ child.href }}">{{ child.name }}</a></div>
                </div>
                </div>
                {% else %}
                <div class="col-sm-4 col-12">
                <div class="category_child">
                <a href="{{ child.href }}"><img src="{{ child.image }}" alt="{{ child.name }}" title="{{ child.name }}" class="img-responsive" /></a>
                <div class="child_name"><a href="{{ child.href }}">{{ child.name }}</a></div>
                </div>
                </div>
                {% endif %}
               {% endfor %}
              {% endif %}
          </div> 
        </div>
          {% endif %}
        {% endfor %}

    </div>    
</div>
</section>

Все за работал отображаются подгатегории определенной категории.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы