Image Replacements

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
sfeher
Captain (CAPT)
Captain (CAPT)
Posts: 220
Joined: Fri Jun 04, 2004 1:58 pm
Location: Steubenville, Ohio

Image Replacements

Post by sfeher » Wed Dec 13, 2017 4:03 am

Ran into a problem that needed a particular solution.
Couldn't find anything in the forums here online, but thought others may find this situation too.... so I thought I'd add this as a handy reference.

The problem:
Converting client into AbleCommerce AC GOLD 12 SR1. They have approx. 25,000 skus. Images in the old system were brought over, but we have a LOT of issues where database field contains incorrect image file names.
a.) The database image field on many items is not null.
b.) The default image will not appear (because the field is not null).
c.) There are hundreds or thousands of potential errors to "find" the images.

Because the image file names are in the database, the cart "thinks" that the image should be displayed. However, since the image file name is wrong, we get a "broken image" display in the browser.

The Solution:
In the ProductImage.ascx page, I added an "OnError" javascript to the page.

Code: Select all

function imgError(image) {
    image.onerror = "";
    image.src = "/assets/_no_image.jpg";
    return true;
}
then, on the image, simply added the onError code to the actual image tag

Code: Select all

<a id="ProductImageUrl" runat="server" class="fancybox-thumbs" data-fancybox-group="thumb" ClientIDMode="Static">
                <asp:Image ID="ProductImage" runat="server" BorderWidth="0" CssClass="productImage" ClientIDMode="Static" itemprop="image" 
                	onerror="imgError(this);" />
            </a>

Bottom line -- now the right " default" image will appear if the browser gets a 404 or 500 error and we can avoid the "broken image' mess....

Hope this helps someone else!

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: Image Replacements

Post by Katie » Wed Dec 13, 2017 11:52 pm

Thanks for taking the time to post this Steve.

We appreciate it :)
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

Post Reply