miércoles, 19 de mayo de 2010

wp-e-commerce upload adding multiple categories to CSV upload

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:

Please select a category you would like to place all products from this CSV into:

'.$category.'';

}




Next we add the category and brand options to the dropdown list of assignable fields.
lines 61 - 69 show:

Product Name
Description
Additional Description
Price
SKU
Weight
Weight Unit
Stock Quantity
Stock Quantity Limit


We are going to add to these so we now have:

Product Name
Description
Additional Description
Price
SKU
Weight
Weight Unit
Stock Quantity
Stock Quantity Limit
Category
Brand


now we change (what is now) line 122 - 123 to read:

$category_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','$id','".$cvs_data2."')";
$wpdb query($category_query);


and add the following two lines underneath:

$brand_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','$id','".$cvs_data2."')";
$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.

2 comentarios: