'>

You can import your products from a comma delimited text file.

An example of a cvs import file would look like this:

Description, Additional Description, Product Name, Price, SKU, weight, weight unit, stock quantity, is limited quantity

', 'wpsc');?> '.print_r($_FILES, true).''); if ($_FILES['csv_file']['name'] != '') { ini_set("auto_detect_line_endings", 1); $file = $_FILES['csv_file']; //exit('
'.print_r($file,true).'
'); if(move_uploaded_file($file['tmp_name'],WPSC_FILE_DIR.$file['name'])){ $content = file_get_contents(WPSC_FILE_DIR.$file['name']); //exit('
'.print_r(WPSC_FILE_DIR.$file['name'], true).'
'); $handle = @fopen(WPSC_FILE_DIR.$file['name'], 'r'); while (($csv_data = @fgetcsv($handle, filesize($handle), ",")) !== false) { $fields = count($csv_data); for ($i=0;$i<$fields;$i++) { if (!is_array($data1[$i])){ $data1[$i] = array(); } array_push($data1[$i], $csv_data[$i]); } } //exit("
".print_r($data1, 1)."
"); $_SESSION['cvs_data'] = $data1; $categories_sql = "SELECT `id`,`name` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1'"; $categories = $wpdb->get_results($categories_sql, ARRAY_A); ?>

For each column, select the field it corresponds to in 'Belongs to'. You can upload as many products as you like.

'.print_r($_SESSION['cvs_data'], true).''); foreach ((array)$data1 as $key => $datum) { ?>

Column ()



There was an error while uploading your csv file."; } } if($_POST['csv_action'] == 'import'){ global $wpdb; $cvs_data = $_SESSION['cvs_data']; //exit('
'.print_r($_SESSION['cvs_data'], true).'
'); $column_data = $_POST['column']; $value_data = $_POST['value_name']; $name = array(); /* foreach ($value_data as $key => $value) { $value_data[$key] = $cvs_data[$key]; } */ //echo('
'.print_r($value_data, true).'
'.print_r($column_data, true).'
'); foreach ($value_data as $key => $value) { $cvs_data2[$value] = $cvs_data[$key]; } //exit('
'.print_r($cvs_data2, true).'
'); $num = count($cvs_data2['name']); for($i =0; $i < $num; $i++){ $cvs_data2['price'][$i] = str_replace('$','',$cvs_data2['price'][$i]); //exit( $cvs_data2['price'][$i]); // exit($key. ' ' . print_r($data)); $query = "('".$cvs_data2['name'][$i]."', '".$cvs_data2['description'][$i]."', '".$cvs_data2['additional_description'][$i]."','".$cvs_data2['price'][$i]."','".$cvs_data2['weight'][$i]."','".$cvs_data2['weight_unit'][$i]."','".$cvs_data2['quantity'][$i]."','".$cvs_data2['quantity_limited'][$i]."')"; $query = "INSERT INTO `".WPSC_TABLE_PRODUCT_LIST."` (name, description, additional_description, price, weight, weight_unit, quantity, quantity_limited) VALUES ".$query; // echo($query); $wpdb->query($query); $id = $wpdb->get_var("SELECT LAST_INSERT_ID() as id FROM `".WPSC_TABLE_PRODUCT_LIST."`"); $meta_query = "INSERT INTO `".WPSC_TABLE_PRODUCTMETA."` VALUES ('', '$id', 'sku', '".$cvs_data2['sku'][$i]."', '0')"; $wpdb->query($meta_query); $category_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','{$id}','".$wpdb->escape($_POST['category'])."')"; $wpdb->query($category_query); $existing_name = get_product_meta($id, 'url_name'); // strip slashes, trim whitespace, convert to lowercase $tidied_name = strtolower(trim(stripslashes($cvs_data2['name'][$i]))); // convert " - " to "-", all other spaces to dashes, and remove all foward slashes. //$url_name = preg_replace(array("/(\s-\s)+/","/(\s)+/", "/(\/)+/"), array("-","-", ""), $tidied_name); $url_name = sanitize_title($tidied_name); //exit('NAMES >>'.$url_name.' '.$existing_name); // Select all similar names, using an escaped version of the URL name $similar_names = (array)$wpdb->get_col("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `product_id` NOT IN('{$id}}') AND `meta_key` IN ('url_name') AND `meta_value` REGEXP '^(".$wpdb->escape(preg_quote($url_name))."){1}[[:digit:]]*$' "); // Check desired name is not taken if(array_search($url_name, $similar_names) !== false) { // If it is, try to add a number to the end, if that is taken, try the next highest number... $j = 0; do { $j++; } while(array_search(($url_name.$j), $similar_names) !== false); // Concatenate the first number found that wasn't taken $url_name .= $j; } // If our URL name is the same as the existing name, do othing more. if($existing_name != $url_name) { update_product_meta($id, 'url_name', $url_name); } } /* $query = "INSERT INTO {$wpdb->prefix}product_list (name, description, addictional_description, price) VALUES ".$query; */ echo "

Success, your products have been upload."; } ?>