Задать вопрос
Ответы пользователя по тегу OpenCart
  • Как вывести определенную категорию товаров на главной странице opencart 3?

    @idpabloo
    Модулем я сделал так контроллер
    <?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>

    В твоем случаи удали чайлды и пропици id своей категории и будет счастье
    Ответ написан
    Комментировать
  • Как вывести подкатегории на Home opencart 3x?

    @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>

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