Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Default product image finally!


saket

Recommended Posts

Posted

Hey I finally figured out how to use a default image for all products!

BACKUP YOUR DATABASE FIRST!

 

Start MYSQL

 

Then type

 

use (name of your database here without parenthesis)

 

update products

set products_image = "default.gif"

where products_image = "ARRAY";

 

Thats it upload your default image into the /catalog/images directory. Make sure it's named default.gif or change it above.

Hope this helped!

Posted

There is an easier way. Change admin/categories.php.

 

Find the line that begins:

 

'products_image' => (($HTTP_POST_VARS['products_image']

 

Delete out that whole line, and replace with:

 

'products_image' => (($HTTP_POST_VARS['products_image'] == '') ? 'xyz_123_default.gif' : tep_db_prepare_input($HTTP_POST_VARS['products_image'])),

 

I'm running a fairly old snapshot, but you should be able to do much the same thing. What the code above does is assign the image xyz_123_default.gif to the Product if the products_image field is left blank. All you then need to do is upload (via FTP) the image and thats it.

 

hth

Posted

Burt I saw your post from a while ago and I could not get it to work. When I right clicked on a broken image on my site and viewed it's location it still said /catalog/images/ARRAY as the location. I have a fairly new snapshot. Anyways I probably just did something wrong but the mysql way worked fine for me. Thanks anyway

Posted

You can make a default image for the categories too

mysql

use (your catalog name)

update categories

set categories_image = "default.gif"

where categories_image is NULL

Posted
What is the syntax for using these commands in phpMyAdmin?  :?:

 

update categories 

set categories_image = "default.gif" 

where categories_image is NULL

 

and for the products..

 

update products

set products_image = "default.gif" 

where products_image is NULL

 

hope it helps

Posted

Well I took a look closer, and it looks like even with the MO PICS contributions, it still uses the product image as usual (I think).. anyway when I run that scrip in phpMyAdmin, it comes up and says:

 

Affected rows: 0

 

SQL-query :

update products

set products_image = "default.gif"

where products_image is NULL

Posted

you have to use the command line for my this method I don't know how to do it with phpmyadmin. And for some reason at least in my snapshot the products_image is filled with ARRAY when you leave it blank instead of NULL like everything else so thats why you need the line

 

where products_image = "ARRAY"

 

instead of using

 

where products_image is NULL

Posted

With a little help from the german community i can present a working version now in some easy steps:

 

1.) get a default-image ready. i?ll refer to it in the scripts as 'default.php'

2.) upload it onto yer webserver (some forget, i swear ;)

3.) a little cleanup for the already existing products, so you won?t have to edit them all:

 

update products set products_image = "default.gif" where products_image is NULL

to change the NULL for no pic in products to 'default.gif' in products(command works with phpmyadmin btw..)

 

update categories set categories_image = "default.gif" where categories_image is NULL

to change the NULL for no pic to 'default.gif' in categories

 

4.) Optional Step - should work without, but we wanna make SURE it does..

ALTER TABLE `categories` CHANGE `categories_image` `categories_image` VARCHAR( 64 ) DEFAULT 'default.gif'

for change of the defaultvalue in categories

 

ALTER TABLE `products` CHANGE `products_image` `products_image` VARCHAR( 64 ) DEFAULT 'default.gif'

for change of the defaultvalue in products

 

5.) Now for the real thing: Open up your admin/categories.php

Replace:

echo tep_draw_hidden_field('products_image', stripslashes($products_image_name));

depending on how much you have hacked already it appears around line 620..

 

Replace it with:

if ($products_image_name) {

   echo tep_draw_hidden_field('products_image', stripslashes($products_image_name));

  } else {

   echo tep_draw_hidden_field('products_image', 'default.gif');

  }

 

That one should do the job DEFINITELY. At least it did it for me. Took ages. Damn :P

Posted

to make it a good hack there is just one little thing that annoyed me: if i view the preview it confrontated me with the "missing picture" phenomenon again. Here?s the solution:

Find and replace somewhere around line 550 in your admin/categories.php:

<?php echo tep_image(DIR_WS_CATALOG_IMAGES . $products_image_name, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $pInfo->products_description; ?>

with the following code:

<?php

//BOF: Default-image hack

//REPLACE: echo tep_image(DIR_WS_CATALOG_IMAGES . $products_image_name, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $pInfo->products_description; with:

if ($products_image_name) {

echo tep_image(DIR_WS_CATALOG_IMAGES . $products_image_name, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $pInfo->products_description;

} else {

echo tep_image(DIR_WS_CATALOG_IMAGES . 'default.gif', $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $pInfo->products_description;

}

//EOF: Default-image hack

?>

Finished! :wink:

 

 

well, i checked out everything. and it works dweet. but i didn?t think of one situation: what if i delete that product? well, with my version - it simply deletes the picture. according to my setup i could chmod as i wanted - it either didnt display my default.gif or would display AND delete. :shock:

 

hm. so a few more configuration steps needed:

Pick your admin/includes/functions/general.php and find somewhere around line 928 depending on the version you got and amount of hacks you implemented... blahblahfazel:

if (file_exists(DIR_FS_CATALOG_IMAGES . $product_image['products_image'])) {

and replace it with:

//BOF: Default-image hack

// REPLACE if (file_exists(DIR_FS_CATALOG_IMAGES . $product_image['products_image'])) {   with

if ((file_exists(DIR_FS_CATALOG_IMAGES . $product_image['products_image'])) && ($product_image['products_image'] != 'default.gif')) { 

//EOF: Default-image hack

 

This does the job. All aspects encountered with default.gif so far. Hopefully. Is this enuff to make it a contribution? Or will this be added to the next snapshot maybe? Just asking cos i?m new to OSCommerce... But it?s sweet, really. Thanks!

Archived

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

×
×
  • Create New...