viernes, 28 de mayo de 2010

wp-e-commerce upload adding images to CSV upload

We've covered uploading multiple categories in wp-e-commerce, but what about images?

It stands to reason that if you are uploading a bunch of products, you will want images to accompany them. This takes a little more work than adding multiple categories, but is significantly easier than adding them one-by-one.

1. Preparing the Images
If you are happy doing bulk resizing/cropping in whichever graphics package you use, then do it! Process your product images so that you have a thumbnail that matches the size defined in your wp-e-commerce installation (96px X 96px is the current default).

Next process your source images again so that you have a large image that is either a manageable size, or sized to your wp-e-commerce product image size settings (128px X 128px is the current default). Once you have thumbnails and full-size images, upload the thumbnails to "wp-content/uploads/wpsc/product_images/thumbnails/" and the full-size to "wp-content/uploads/wpsc/product_images/". You can now move onto step 2 "Importing".

If you aren't happy batch-processing images you can create a directory called "'wp-content/uploads/wpsc/product_images/temp" and upload all your product images there. Please ensure that the images are at a manageable size (i.e. less than 1000px wide or high).

Next download and save a copy of the "imgprocess.php" script we cobbled together (remove the XXX from the extension) - n.b. this script is largely based on a great function here

Adjust the thumbnail size variables ($thumbwidth and $thumbheight) on lines 3-4 to correspond with the thumbnail sizes specified in wp-e-commerce (default is 96px X 96px). If you want your large images processed as well then add the relevant dimensions to the $largewidth and $largeheight variables on lines 6 and 7. Alternatively, leave them at 0 if you don't want to resize your large images. Please note that this is a basic script so it only crops images to the exact sizes specified. If you want your large images to be scaled, you will have to add that functionality yourself.

Once you have made your adjustments, upload the script to the root of your WordPress installation (in most cases yoursite.com/imgprocess.php). Please note that this script has not been extensively tested, and you run it very much at your own risk. We highly recommend running it in a test environment first and take no responsibility for anything (from server failure to hives or plagues of locusts) that occurs from the moment you run it!!

If you chose to continue, run the script by entering the location into your browser (in most cases yoursite.com/imgprocess.php). The script will take a while to execute, but all being well you will see a big ugly message saying "Images processed". Your thumbnails directory should now be populated with the thumbnails you created.

If you chose not to resize the large images then simply copy the images from "wp-content/uploads/wpsc/product_images/temp" to "wp-content/uploads/wpsc/product_images". Otherwise, your resized large images should be in wp-content/uploads/wpsc/product_images/'.

Next delete "wp-content/uploads/wpsc/product_images/temp" and delete imgprocess.php.

2. Importing
Open wp-e-commerce/wpsc-admin/includes/settings-pages/import.php
locate the option list:

Product Name
Description
...etc


and add the following option value:

Image


Next locate the line

$existing_name = get_product_meta($id, 'url_name');


and add the following above it so it reads:

$image_query = "INSERT INTO `".WPSC_TABLE_PRODUCT_IMAGES."` (product_id,image ) VALUES ('$id','".$cvs_data2."')";
$wpdb query($image_query);
$imageid = $wpdb get_var("SELECT LAST_INSERT_ID() as id FROM `".WPSC_TABLE_PRODUCT_IMAGES."`");
//now add image id to product
$image_query2 = "UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET image = ".$imageid." WHERE id=".$id;
$wpdb query($image_query2);
$existing_name = get_product_meta($id, 'url_name');


Now add a column to your product list csv that you wish to upload and add the name of each image uploaded to the relevant image
e.g.
SKU, Name, Price, Image
001, Shoe, 100, shoe.jpg
002, Hat, 20, hat.jpg

Upload the csv as normal remembering to assign 'Image' to the relevant column, and your products should now be loaded complete with images.

No hay comentarios:

Publicar un comentario