Post by stfng » Wed Feb 17, 2016 2:36 pm

Hello there,

I'm trying to hide the products with no image from displaying in the category. I know there are some extensions available that disable the products with no image but I don't want to disable them. This way when we add images, they'll just start to show without having to enable them again.

Thanks..

Newbie

Posts

Joined
Wed Feb 17, 2016 2:31 pm

Post by OSWorX » Thu Feb 18, 2016 12:34 am

Simply add 1 line into the controller category.php and check if an image exists.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by stfng » Thu Feb 18, 2016 5:20 am

Could you please give me an example what that 1 line is?

Newbie

Posts

Joined
Wed Feb 17, 2016 2:31 pm

Post by OSWorX » Thu Feb 18, 2016 5:55 am

stfng wrote:Could you please give me an example what that 1 line is?
Basically it is only a simple

Code: Select all

continue;
at the right place.

Guess now you want to know where?

Well, search for

Code: Select all

if ($result['image']) {
(in OC 2.1.0.1 this would be line 183)
The whole section should be that:

Code: Select all

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'));
				}
and replace by that:

Code: Select all

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 {
					continue;     
					$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
				}
From now on all products without an image are not displayed.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by stfng » Thu Feb 18, 2016 8:44 am

Thank you so much for your response OSWorx however adding continue; didn't work. Products with no image are still showing under category.

Newbie

Posts

Joined
Wed Feb 17, 2016 2:31 pm

Post by OSWorX » Thu Feb 18, 2016 4:34 pm

stfng wrote:Thank you so much for your response OSWorx however adding continue; didn't work. Products with no image are still showing under category.
I have tested it - otherwise I would not post ist.
You can contact me and I will check it for you.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by hero12 » Sun Apr 05, 2020 6:05 pm

Hello @Osworks

I checked for my version of opencart 3 and found the same code so I applied your changes in /catalog/controller/product/category.php

there is no result, do you know if that applies for opencart 3?

regards

Newbie

Posts

Joined
Thu Apr 02, 2020 3:54 am

Post by OSWorX » Sun Apr 05, 2020 6:40 pm

hero12 wrote:
Sun Apr 05, 2020 6:05 pm
Hello @Osworks

I checked for my version of opencart 3 and found the same code so I applied your changes in /catalog/controller/product/category.php

there is no result, do you know if that applies for opencart 3?

regards
OC 3.0.2.0 (should also work in other 3.0.x versions):
Original code:

Code: Select all

foreach ($results as $result) {
				if ($result['image']) {
					$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
				} else {
					$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
				}
New code:

Code: Select all

if ($result['image']) {
	$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
	continue;
	$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
OR:

Code: Select all

if ($result['image']) {
	$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
	continue;
}
The 2nd replace simply the second code part after the } else { with continue.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 50 guests