Post by sagraphics » Fri Feb 02, 2018 6:08 pm

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.

New member

Posts

Joined
Sat Nov 11, 2017 3:41 am

Post by IP_CAM » Sat Feb 03, 2018 12:59 am

Well, this is not the case in any regular OpenCart OC-2 default Versions,
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.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by sagraphics » Wed Feb 21, 2018 8:27 pm

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.

New member

Posts

Joined
Sat Nov 11, 2017 3:41 am

Post by IP_CAM » Wed Feb 21, 2018 10:19 pm

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

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.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by sagraphics » Thu Feb 22, 2018 12:14 am

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)

New member

Posts

Joined
Sat Nov 11, 2017 3:41 am

Post by IP_CAM » Thu Feb 22, 2018 3:56 am

Well, it's a highly customized Theme you use, you therefore better get
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.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by sagraphics » Thu Feb 22, 2018 8:34 pm

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.

New member

Posts

Joined
Sat Nov 11, 2017 3:41 am
Who is online

Users browsing this forum: No registered users and 74 guests