Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Show a default image if image not found


Recommended Posts

Hi all in Frozen CE BS is there a way that if an image file is not found a default image can be shown

So just to clarify the image name and locate is set for the product but the image does not exist on the server can I have the page show a default image?

Change to below
image.png.1f1aec4703884508ed18dff00699b2c9.png
to this image.png.f5e54cfd7a09e1518d64da7bd9456b59.png

Link to comment
Share on other sites

I found this from 2014 and it seems to have done the job, any comments if the code should be improved for 2019

You need to modify the tep_image() function located in catalog/includes/function/html_output.php

Replace...

if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
  return false;
}

With...

if (!is_file($src)) {
$src = "images/no_image.jpg";
}
Link to comment
Share on other sites

The better solution is to install the image thumbnailer addon. It does what you want but also, usually, improves the appearance and reduces the size of the images.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Is this fall-out from a migration or an admin accident? Have you got image entries in the products/products_images table with no corresponding files?

I believe if an image tag relates to a non-existent image, you will always get the alt text - though forcing a background image might work behind it, my guess is that it would look bad.

Priority should be to put the images back in the place it's looking for them, or run a query against the database to update the entries to the new image path.

Backup plan: though a modification to the image function to check for image existence would work, the better approach would be a wrapper function for product images so you only get the overhead on those local files that might not exist. Faster function to check for local file existence is stream_resolve_include_path() instead of file_exists()

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

@BrockleyJohn Non of the above.
We deal in thousands of small parts for the products we have and at times we are just unable to locate images. We upload / update products using easy populate with the partnumber.jpg as the image name. We wget the images from the distributors and ftp them on to the server. Previously we would then go threw manualy updating the products which don't have images with our default no_image.jpg but now with the change above we no longer need to worry

Link to comment
Share on other sites

There is a very simple solution that could be built into the core to take care of this permanently by using "onerror".

<img src="https://www.jcmagpie.com/images/broken.jpg" alt="Oh no the image is broken" onerror="this.src='https://www.jcmagpie.com/images/jcmagpie-2.png';">

 

 

Link to comment
Share on other sites

1 hour ago, SCH_001 said:

@BrockleyJohn Non of the above.
We deal in thousands of small parts for the products we have and at times we are just unable to locate images. We upload / update products using easy populate with the partnumber.jpg as the image name. We wget the images from the distributors and ftp them on to the server. Previously we would then go threw manualy updating the products which don't have images with our default no_image.jpg but now with the change above we no longer need to worry

Sounds like your import should be doing all that automatically - get the file and store it, save instead noimage if it doesn't exist

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

1 hour ago, Heatherbell said:

@Jack_mcs

I'm missing something - I see it can add a watermark to all images but I can't find how to add an image if no image exists in the instructions for the addon.

This works by default. Just upload the "no_image_available_150_150.gif" to your image folder and replace it with a custom no image pic if you wish.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...