Reputation: 115
I'm looking for a way to show the category thumbnail in the menu. Is this possible?
Specifically for OpenCart 3.
Upvotes: 0
Views: 1950
Reputation: 486
for submenu use:
$children_data[] = array(
'image' => $child['image'] ? $this->model_tool_image->resize($child['image'], 20, 20) : false,
or
'image' => $child['image'] ? $this->model_tool_image->resize($child['image'], 20, 20) : $this->model_tool_image->resize('your-default-image.jpg', 20, 20),
in template
{% for child in children %}
<li><a href="{{ child.href }}">{% if child.image %}<img src="{{ child.image }}" alt="{{ child.name }}" />{% endif %}{{ child.name }}</a></li>
{% endfor %}
If missed something, follow here
Upvotes: 0
Reputation: 3000
OpenCart 3.0.2.0, Default theme
Open this file:
catalog\controller\common\menu.php
Find:
$this->load->model('catalog/product');
Add after it:
$this->load->model('tool/image');
Find:
$data['categories'][] = array(
Replace with:
if($category['image']){
$image = $this->model_tool_image->resize($category['image'], 30, 30);
} else {
$image = false;
}
$data['categories'][] = array(
'image' => $image,
Then open this file:
catalog\view\theme\default\template\common\menu.twig
Find:
{{ category.name }}
There are three occurrence, add before first and last one:
<img src="{{ category.image }}" alt="{{ category.name }}"/>{% endif %}
Here is the result:
Upvotes: 1