Answer the question
In order to leave comments, you need to log in
How to display a specific product category on the main page of opencart 3?
How to display a specific product category on the main page of opencart?
Answer the question
In order to leave comments, you need to log in
I myself made a module with similar functionality, only for version 2.3. You can try and remake by analogy, but for your version of OpenCart.
Here's how it works for me.
And this is how it looks in the admin panel.
Link to the module.
I made the controller as a module
<?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);
}
}
<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>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question