Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Turn off Category & Product Images if you don't have one


srfrantz

Recommended Posts

I recently installed OSC 2.3 for a client who had a previous store on a different host running 2.2.

 

After uploading all the images, I discovered that she hadn't input any for categories, but the default layout loop displayed the ugly red x placeholder box for them. (I know most browsers don't show that by default, but I have it turned on so I can quickly spot any missing images when designing/coding new sites)

 

this is a very quick and easy fix, and I'm surprised wasn't coded in to begin with

 

find this code in the index.php about line 73:

echo '		<td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories['categories_name'] . '</a></td>' . "\n";

 

replace it with this:

  echo '<td align="center" class="smallText" width="' . $width . '" valign="top">';
  echo '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
  //don't show category image if there isn't one
 if ($categories['categories_image']!="") {
  echo tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' ;
}
  echo $categories['categories_name'] . '</a></td>' . "\n";

 

and if you have products that don't have an image here's how to turn off the placeholder and replace it with a "image not available" or other message if desired.

 

find this in includes/modules/product_listing.php at line 127

	  case 'PRODUCT_LIST_IMAGE':
		if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '		<td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
		} else {
		  $prod_list_contents .= '		<td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
		}

 

and change it to this:

 

case 'PRODUCT_LIST_IMAGE':

//see if there is an image and build the code string for it
	  $ImageCode = "";
	  if ($listing['products_image']!="") { $ImageCode = tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);}
	  else { $ImageCode = "no image available";}

		if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '		<td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $ImageCode . '</a></td>';
		} else {
		  $prod_list_contents .= '		<td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $ImageCode . '</a></td>';
		}

 

hope this helps others. and if I've done something wrong please let me know and correct the code.

 

I am a completely self taught old guy, so I've never had any best practices taught to me.

but have benefitted from support sites like this so trying to give back

 

thanks and happy coding!

Link to comment
Share on other sites

There is already a built in method. ;)

 

 

admin->images->Image Required set it to false

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...