Upload images and descriptions to WP e-Commerce v3.8 using CSV

 

  1. Load all the full size images to the location ../wp-content/uploads/YEAR/MONTH/ folder YEAR is the current year and MONTH is the current month and is always 2 digits eg Feb = 02
  2. Create a CSV file that looks something like :-

    SKU, Name, Price, Image

    001, Shoe, 100, 2011/04/1.jpg

    002, Hat, 20, 2011/04/2.jpg

    003, Sock, 23, 2011/04/3.jpg

    The string before the image name is the same and should reflect the YEAR/MONTH/ that was used in step 1. to upload the images to.

  3. Open wp-e-commerce/wpsc-admin/includes/settings-pages/import.php
  4. Find the line :-

    <option value=’name’><?php _e(‘Product Name’, ‘wpsc’); ?></option> and add the following line to the end of the blocks defintions :-

    <option value=’imagename’><?php _e(‘Image’, ‘wpsc’); ?></</option>

  5. Next find the line (maybe #162):-

    wp_set_object_terms( $product_id , array( (int)$_POST['category'] ) , ‘wpsc_product_category

    and add the following directly underneath it:-

    if ( $cvs_data2['imagename'][$i] != ” ){

    //need the full location of the file so first we get the upload directory

    $upload_dir = wp_upload_dir();

    //now build the file location

    $filename = $upload_dir['baseurl'] . ‘/’ . trim( $cvs_data2['imagename'][$i] );

    //we also need to store just the file location from within the upload directory

    $metafilename = trim( $cvs_data2['imagename'][$i] );

    //establish filetype

    $wp_filetype = wp_check_filetype(basename($filename), null );

    //build our attachment array

    $attachment = array(

    ‘post_mime_type’ => $wp_filetype['type'],

    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)),

    ‘post_content’ => ”,

    ‘post_status’ => ‘inherit’

    );

    //insert attachment data into WP IMPORTANT – we need to use $metafilename here NOT the filename with the full URL

    $attach_id = wp_insert_attachment( $attachment, $metafilename, $product_id );

    // you must first include the image.php file

    // for the function wp_generate_attachment_metadata() to work

    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);

    //generate metadata

    $attach_data = wp_generate_attachment_metadata( $attach_id, $metafilename );

    wp_update_attachment_metadata( $attach_id, $attach_data );

    //finished!

    }

  6. Go to Dashboard>Settings>Store>Import and enter the name of the import.csv file with the information in the click Import
  7. Select the Product Status to be Published and then associate the headings of the csv file with the values in the drop down boxes.
  8. Next select the category that they will all go into and click Import.
  9. All the data and the images will then be imported into the WP e-Commerce site.

Comments are closed.