Answer the question
In order to leave comments, you need to log in
How to display image in opencart menu?
Tell me how to display a category image in the opencart menu.
In the templete/common/ folder, the header.tpl file was added to the right place:
<?php if ($category['image']) { ?>
<img src="<?php echo $category['image']; ?>"/>
<?php } else { ?>
<?php } ?>
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Уровень 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'])
);
}
// Уровень 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'])
);
}
}
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
Answer the question
In order to leave comments, you need to log in
Pictures are displayed in categories, where it is implemented like this:
<div class="well red-links">
<?php if ($thumb) { ?>
<div class="pull-left"><img src="<?php echo $thumb; ?>" alt="<?php echo $heading_title; ?>" title="<?php echo $heading_title; ?>" class="img-thumbnail" style="margin: 0 10px 5px 0" /></div>
<?php } ?>
<?php if ($description) { ?>
<?php echo $description; ?>
<?php } ?>
<div class="clearfix"></div>
</div>
....
$this->load->model('tool/image');
....
if ($category_info['image']) {
$data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
} else {
$data['thumb'] = '';
}
...
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
...
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
if ($category['image']) {
$image = $this->model_tool_image->resize($category['image'], 100, 50);
} else {
$image = false;
}
<img src="<?php echo $category['thumb']; ?>" border="0">
In short, you need to
add before
if ($category['image']) {
$image = $this->model_tool_image->resize($category['image'], 50, 50);
} else {
$image = $this->model_tool_image->resize('no-image.png', 50, 50);
}
$data['categories'][] = array(
'name' => $category['name'],
$this->load->model('tool/image');
if it is not done above in the code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question