netfrugal Posted February 23, 2005 Share Posted February 23, 2005 I've been searching for a customer importing contribution via csv. I found a couple online that are able to import products, but not customers. Does anyone know of one that is available? Also, this one I found: Basic CSV Importer - was submitted back in 2002. Works great with products, but I'd like to make it work with customer rather than products. So after some hair pulling hours of testing I've not been able to make it work. here's the code: require('includes/application_top.php'); if ($HTTP_GET_VARS['action']) { switch ($HTTP_GET_VARS['action']) { case 'import': //retrieve the code for default language from database $sql_get_default_language = 'SELECT configuration_value FROM ' . TABLE_CONFIGURATION . ' '; $sql_get_default_language .= 'WHERE configuration_key = "DEFAULT_LANGUAGE"'; $tep_import_res = tep_db_query($sql_get_default_language); $default_language_array = tep_db_fetch_array ($tep_import_res); unset ($sql_get_default_language, $tep_import_res); $sql_get_default_language = 'SELECT languages_id FROM ' . TABLE_LANGUAGES . ' '; $sql_get_default_laguage .= 'where code = "' . $default_language_array['configuration_value'] . '"'; unset ($default_language_array); $tep_import_res = tep_db_query($sql_get_default_language); $default_language_array = tep_db_fetch_array ($tep_import_res); $default_language_id = $default_language_array['languages_id']; unset ($default_language_array, $sql_get_default_language); //copy the uploaded CSV file into the images directory. //it seems like a relevant enough location - the file is //only temporary after all! if ( ($csv_to_import != 'none') && ($csv_to_import != '') ) { $csv_file_location = DIR_FS_CATALOG_IMAGES . $csv_to_import_name; if (file_exists($csv_file_location)) @unlink($csv_file_location); copy($csv_to_import, $csv_file_location); $parse_csv = true; } else { $messageStack->add('No file specified; Import cancelled.', 'error'); $parse_csv = false; } if ($parse_csv) { $csv_fp = fopen ($csv_file_location, "r"); fGetS ($csv_fp, 4096); $rows = 0; while ($data = fGetCsv ($csv_fp, 10000, ",")) { $rows++; $csv = array(); $csv['name'] = $data[0]; $csv['description'] = $data[1]; $csv['quantity'] = $data[2]; $csv['model'] = $data[3]; $csv['image'] = $data[4]; $csv['url'] = $data[5]; $csv['price'] = $data[6]; $csv['weight'] = $data[7]; $csv['tax_class_id'] = $data[8]; $csv['manufacturers_id'] = $data[9]; $csv['categories_id'] = $data[10]; $csv['date_inserted'] = 'now()'; $csv['status'] = 1; //hardcoded for now - will change as necessary $sql_data_array = array('products_quantity' => tep_db_prepare_input($csv['quantity']), 'products_model' => tep_db_prepare_input($csv['model']), 'products_image' => tep_db_prepare_input($csv['image']), 'products_price' => tep_db_prepare_input($csv['price']), 'products_date_added' => tep_db_prepare_input($csv['date_inserted']), 'products_weight' => tep_db_prepare_input($csv['weight']), 'products_status' => tep_db_prepare_input($csv['status']), 'products_tax_class_id' => tep_db_prepare_input($csv['tax_class_id']), 'manufacturers_id' => tep_db_prepare_input($csv['manufacturers_id']) ); tep_db_perform(TABLE_PRODUCTS, $sql_data_array); $inserted_product_id = tep_db_insert_id(); unset($sql_data_array); $sql_data_array = array('products_id' => tep_db_prepare_input($inserted_product_id), 'categories_id' => tep_db_prepare_input($csv['categories_id']) ); tep_db_perform(TABLE_PRODUCTS_TO_CATEGORIES, $sql_data_array); unset($sql_data_array); $sql_data_array = array('products_id' => tep_db_prepare_input($inserted_product_id), 'language_id' => tep_db_prepare_input($default_language_id), 'products_name' => tep_db_prepare_input($csv['name']), 'products_description' => tep_db_prepare_input($csv['description']), 'products_url' => tep_db_prepare_input($csv['url']) ); tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array); unset($sql_data_array, $csv); } fclose ($csv_fp); @unlink ($csv_file_location); } } } ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <link rel="stylesheet" type="text/css" href="includes/stylesheet.css"> <script language="javascript" src="includes/general.js"></script> </head> <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();"> <div id="spiffycalendar" class="text"></div> <!-- header //--> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <!-- body //--> <table border="0" width="100%" cellspacing="2" cellpadding="2"> <tr> <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft"> <!-- left_navigation //--> <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?> <!-- left_navigation_eof //--> </table></td> <!-- body_text //--> <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="pageHeading">Catalog Import Wizard</td> <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td> </tr> </table></td> </tr> <tr> <td> <?php if ($HTTP_GET_VARS['action']) { switch ($HTTP_GET_VARS['action']) { case 'import': ?> <b><?php echo $rows; ?></b> records were successfully imported from the CSV file. <?php } } else { echo tep_draw_form ('import', 'import.php', 'action=import', 'post', 'enctype="multipart/form-data"'); ?> File to import:<br> <?php echo tep_draw_file_field('csv_to_import', true); ?><br> File must be in the CSV format exported from Microsoft Excel or similar<br> spreadsheet manipulation program<br>. <?php echo tep_image_submit('button_save.gif', IMAGE_SAVE); ?> <?php } ?> </td> </tr> </table></td> <!-- body_text_eof //--> </tr> </table> <!-- body_eof //--> <!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> <br> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> Everything imports to the'products' and 'productstocategories' tables. I've tried switching these to customers and changing the fields to match what is in the customers table, but everything still gets sent to products. Where am I going wrong? Has anyone had any luck with importing customers? Marc PS. the link to this particular contribution is: Here Quote Link to comment Share on other sites More sharing options...
Guest Posted February 23, 2005 Share Posted February 23, 2005 easypopulate is the current for products. for customers, it is a bit complicated, as there are quite a few tables to write to. will take a bit of work. how many customers are you talking about? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.