How to bulk upload to more than one category with the excellent Wp-e-commerce plugin.
In our case, we needed to assign each product to a category and a brand (e.g. Category: Jeans, Brand: Levis). To do this, we removed the bulk ‘add to category’ dropdown from the bottom of the import page and added a category and brand option to the dropdowns that are used to assign columns in the uploaded .csv file. Here’s how…
Open wp-e-commerce/wpsc-admin/includes/settings-pages/import.php
As we are going to assign each item to its own category and brand, the category dropdown at the bottom of the upload page is no longer relevant. So, we remove lines 77 – 85:
<label for='category'>Please select a category you would like to place all products from this CSV into:</label>
<select id='category' name='category'>
<?php
foreach($categories as $category){
echo '<option value="'.$category['id'].'">'.$category['name'].'</option>';
}
?>
</select>
Next we add the category and brand options to the dropdown list of assignable fields.
lines 61 – 69 show:
<option value='name'>Product Name</option> <option value='description'>Description</option> <option value='additional_description'>Additional Description</option> <option value='price'>Price</option> <option value='sku'>SKU</option> <option value='weight'>Weight</option> <option value='weight_unit'>Weight Unit</option> <option value='quantity'>Stock Quantity</option> <option value='quantity_limited'>Stock Quantity Limit</option>
We are going to add to these so we now have:
<option value='name'>Product Name</option> <option value='description'>Description</option> <option value='additional_description'>Additional Description</option> <option value='price'>Price</option> <option value='sku'>SKU</option> <option value='weight'>Weight</option> <option value='weight_unit'>Weight Unit</option> <option value='quantity'>Stock Quantity</option> <option value='quantity_limited'>Stock Quantity Limit</option> <option value='category'>Category</option> <option value='brand'>Brand</option>
now we change (what is now) line 122 – 123 to read:
$category_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','$id','".$cvs_data2['category'][$i]."')";
$wpdb->query($category_query);
and add the following two lines underneath:
$brand_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','$id','".$cvs_data2['brand'][$i]."')";
$wpdb->query($brand_query);
This is simply adding the category and brand id to the WPSC_TABLE_ITEM_CATEGORY_ASSOC table.
Remember to add the Category IDs to your csv file and NOT the category name. Alternatively you could extend this tutorial by looking up the Category ID using the Category Name and inserting that.

Hello,
Great write-up! Do you have an updated set of instructions for 3.8 like you do on the thumbnail article? I can’t seem to get this working now with 3.8.
Thanks,
Hi John,
Glad they were of use. I will review the code and get back to you asap.
Didn“t work in 3.8, think you should update!
hey man nice work… i was trying to do the same thing with the updated version. unfortunately no luck… would love to see it working with categories and brands…
Hey guys, I think i have a solution… using the same file (import.php) mentioned above…
deleted this
:
<?php
foreach ( $categories as $category ) {
echo 'term_id . '">' . $category->name . '';
}
?>
added this around line 87
added this around line 125
'brand' => esc_attr( $cvs_data2['brand'][$i] ),
'category' => esc_attr( $cvs_data2['category'][$i] ),
replace the previous comments first step with… REMOVE lines 93-100… using the latest version of wp and wp e-commerce to date of this post…
Hey, Matt. I figured this out in WPEC 3.8. The change is pretty simple. You remove the category dropdown and add a new option to the list of assignable fields just as you did above. Then, you change this:
wp_set_object_terms( $product_id , array( (int)$_POST['category'] ) , ‘wpsc_product_category’ );
To this:
wp_set_object_terms( $product_id , $cvs_data2['category'][$i] , ‘wpsc_product_category’ );
The category column in the CSV can contain the category name, slug or (I believe but have not tested) the category ID. If the Category doesn’t exist, it will be created on the fly and then the product will be assigned to it. My solution could use another person testing and validating it but it worked well for me while importing 5000 products.
Thanks!
kcm
John, Mauro, Gavin and Kevin -
see http://www.haycroftmedia.com/archives/307/wp-e-commerce-upload-adding-multiple-categories-to-csv-upload-updated-for-3-8#more-307 for an updated post for 3.8
Sorry it took a while but i’m spending Easter on a farm in semi-desert and the connection is painfully slow!
Kevin – thanks for your comment – I didn’t realise you could use name or slug as well as ID (didn’t look the function up as my connection is so slow) – good to know. I did pretty much what you suggested but included a second category as well.
Gavin, did your solution work for you?
Hi
please help
-the product page in menu is gone! no navigation at all,
-using new twenty-eleven theme.
-no luck on importing any kind of category, in csv from zen cart and has parent and sub cats in it so I just select category in the import for the 5 cats. I added all the categories manually imported again no luck.
the imgimport.php never worked error
_o(“Not a Valid Image! (“.$e.”) — “.$src);$r=0;
line 27
the images have to be in the root upload directory to work.
all this I can live with but the mystery is how to maintain HTML for description on import.
http://newbusybee.busybeeapp.com/?wpsc-product=7210-blueberry-ladies-elastic-waist-skirt
If there is a paid plugin for the shop I would buy it if it works. nothing seems to be reliable I have looked at the pages from the folks above an the only one that looks like you have had any success ishttp://www.amazingbattery.com/ please share your success and how you put it together.
oh yah sidebar does not work.
Chris,
This post relates to an older version of WPEC.
Please see http://www.haycroftmedia.com/archives/307/wp-e-commerce-upload-adding-multiple-categories-to-csv-upload-updated-for-3-8 for an updated post.
Hi,
Thanks so much for this great tutorial, I was able to combine this tutorial with the csv with images tutorial and everything worked smoothly.
But I have one major problem, I have a large number of categories and manually extracting the category ids will take ages. I was wondering if this tutorial could be extended as was suggested here:
Alternatively you could extend this tutorial by looking up the Category ID using the Category Name and inserting that.
Many thanks!
Hi Steve,
Take a look at the plugin I wrote: http://www.haycroftmedia.com/archives/343/plugin-wpec-cat-importer
This allows for categories to be entered by name as well as grand-parent, parent, child … category structures. Hope that solves your problem.