I wondered if anybody could be of any help... We have a single category image selected for each category, but on the front end, each time you refresh the page, the category image changes to a random image of a product in that category. Wouldn't necessarily be a big issue, except, when we delete a product and that products image is removed, sometimes the category image shows the default not available placeholder.
Well, this is not the case in any regular OpenCart OC-2 default Versions,
as I am aware of...
Ernie
as I am aware of...
Ernie
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
I have found where our template sets the random category image from the products in the category controller.php:
$data['categories'] = array();
$results = $this->model_catalog_category->getCategories($category_id);
foreach ($results as $result) {
$filter_data = array(
'filter_category_id' => $result['category_id'],
'filter_sub_category' => true
);
$randomCategoryProduct = $this->model_catalog_product->getRandomProduct($result['category_id']);
$totalProducts = $this->model_catalog_product->getTotalProducts($filter_data);
if ($randomCategoryProduct['image']) {
$image = $this->model_tool_image->resize($randomCategoryProduct['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'));
}
if (is_null($image)) {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
$data['categories'][] = array(
'name' => $result['name'],
'totalProducts' => $totalProducts,
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
'image' => $image
);
}
But I can't work out how to pull the category image instead of a random product.
Changing:
$this->model_tool_image->resize($randomCategoryProduct['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
To:
$this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
Just shows a placeholder image.
$data['categories'] = array();
$results = $this->model_catalog_category->getCategories($category_id);
foreach ($results as $result) {
$filter_data = array(
'filter_category_id' => $result['category_id'],
'filter_sub_category' => true
);
$randomCategoryProduct = $this->model_catalog_product->getRandomProduct($result['category_id']);
$totalProducts = $this->model_catalog_product->getTotalProducts($filter_data);
if ($randomCategoryProduct['image']) {
$image = $this->model_tool_image->resize($randomCategoryProduct['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'));
}
if (is_null($image)) {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
$data['categories'][] = array(
'name' => $result['name'],
'totalProducts' => $totalProducts,
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
'image' => $image
);
}
But I can't work out how to pull the category image instead of a random product.
Changing:
$this->model_tool_image->resize($randomCategoryProduct['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
To:
$this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
Just shows a placeholder image.
Well, just check the default:
catalog/controller/product/category.php
then, you'll find out about it. And next time, just mention, what Custom Theme
you use, if you really care, to find some answers.
Good Luck
Ernie
catalog/controller/product/category.php
then, you'll find out about it. And next time, just mention, what Custom Theme
you use, if you really care, to find some answers.
Good Luck
Ernie
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
I don't know the theme as I didn't build the site - I inherited it from another company who are no longer around. I have checked the default, and if I replace the custom code with the default code in controller.php no image appears at all, just an error message of (Notice: Undefined index: totalProducts in /var/www/vhosts/remnanthousefabric.co.uk/httpdocs/catalog/view/theme/remnant/template/product/category.tpl on line 46 Products)
Well, it's a highly customized Theme you use, you therefore better get
professional assistance.
Good Luck
Ernie
---
remnanthousefabric.co.uk
---
professional assistance.
Good Luck
Ernie
---
remnanthousefabric.co.uk
---
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
I just need some help in replacing the randomly picked product image for the static category image - I'm pretty new to opencart and it's file structure and which calls to make.
Who is online
Users browsing this forum: Bing [Bot] and 137 guests