Guest Posted December 19, 2003 Share Posted December 19, 2003 Hi, I'm looking at moving a clients website over to OSC from Interchange and would like to know if anyone has ever come across, or knows about, an import tool from Interchange to OSC. This would seriously make the transition a whole lot easier and would be of great benefit. Thanks for any advice anyone can give on this matter. Kind regards Goody :) Link to comment Share on other sites More sharing options...
Guest Posted December 20, 2003 Share Posted December 20, 2003 Anyone? Link to comment Share on other sites More sharing options...
ravitek Posted February 15, 2004 Share Posted February 15, 2004 Hello, I found a script and I tried to install PHP all day as this is what it needs to run. I emailed the author today and still waiting for a reply. Here's the script, and comments from author, if you get it to work, can you help me. it does look at my products.txt file and has some text parsing error with some fields. Maybe you could develop it soem more. here you go................. #!/usr/bin/php -q <?php /* IC2OSC - Version 0.1 Copyright © 2003 Aaron Bockover Aaron Bockover: aaron *AT* aaronbock ~DOT~ net http://www.aaronbock.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* WARNING: This software has the capability of causing drastic changes to database tables, specifically, tables relating to the osCommerce (OSC) PHP software. If you provide data for the variables defined below and run this program, you do so at your own risk! It *IS* possible to enable this software to completely DELETE the data from 5 OSC tables. YOU MUST EXPLICITLY SET ALL VARIABLES REQUIRED FOR THIS PROGRAM TO RUN PROPERLY! Doing so places all results, whether intended or otherwise, directly on you, the one modifying the values of the variables below. PLEASE BE CAREFUL! Review this code carefully, and discover exactly what it can do! This program *does* work, but if used improperly, it can cause serious data loss. PLEASE BACK UP ALL OSC TABLES BEFORE RUNNING THIS PROGRAM! Thank you, Aaron Bockover */ /*********** BEGIN CONFIGURATION *********************************************/ // IC products file $ic[products_file] = "products.txt"; // OSC database $osc[db_host] = ""; $osc[db_user] = ""; $osc[db_pass] = ""; $osc[db_dbse] = ""; // IC->OSC merge-method $osc[merge_method] = ""; // {FLUSH|APPEND} // Field Map ** NOTE: the products table MUST come first!!!! // OSC TABLE IC FIELD OSC FIELD $osc[field_map] [products] [sku] = "products_model"; $osc[field_map] [products] [price] = "products_price"; //$osc[field_map] [products] [weight] = "products_weight"; //$osc[field_map] [products] [image] = "products_image"; $osc[field_map] [products_description] [description] = "products_name"; $osc[field_map] [products_description] [comment] = "products_description"; // Category Update $osc[category_update] = "YES"; // {YES|NO} /*********** END CONFIGURATION ***********************************************/ /* WARNING: Chaning code below may have drastic effects on your OSC DB!!!!!! */ /*********** END CONFIGURATION ***********************************************/ /* Function to get an OSC category ID based on name, or build an OSC category if one doesn't exist (provided $osc[category_update] == "YES") */ function make_osc_category($name, $parent_id = 0) { global $osc_db_link, $osc; $catid = 0; $query = "SELECT categories_id FROM categories_description WHERE categories_name = '" . addslashes($name) . "' LIMIT 1"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { $catid = mysql_fetch_assoc($result); $catid = $catid[categories_id]; } else if($osc[category_update] == "YES") { /* make new category */ $query = "INSERT INTO categories (parent_id, sort_order, date_added, last_modified) VALUES ('$parent_id', '1', NOW(), NOW())"; mysql_query($query); $catid = mysql_insert_id($osc_db_link); $query = "INSERT INTO categories_description (categories_id, categories_name) VALUES ('$catid', '" . addslashes($name) . "')"; $result = mysql_query($query); } return $catid; } /* I like C... */ $products = array(); $products_t = array(); $fields = array(); $current = 0; echo "\n<---IC2OSC Product Database Convertor--->\n\n"; /* Load products into array (each product = one line by \r) */ echo " * Loading Interchange product database...\n"; $products_t = file($ic[products_file]) or die("Cannot load product database\n"); /* Process each product entry and convert to field-key array */ echo " * Building keyed array of products from Interchange database...\n"; foreach($products_t as $product) { $parts = explode("\t", $product); $t_parts = array(); /* build list of fields for keying of product entries */ if($current++ == 0) { $fields = $parts; continue; } /* build keyed sub-array */ $n_parts = count($parts); for($i = 0; $i < $n_parts; $i++) { $t_parts[$fields[$i]] = $parts[$i]; } /* append product array */ $products[] = $t_parts; } /* Connect to OSC MySQL database */ echo " * Connecting to OSC MySQL Server...\n"; $osc_db_link = @mysql_connect($osc[db_host], $osc[db_user], $osc[db_pass]) or die("Cannot connect to OSC MySQL server ($osc[db_host]): " . mysql_error()); echo " * Selecting OSC database...\n"; @mysql_select_db($osc[db_dbse], $osc_db_link) or die("Cannot select OSC MySQL database ($osc[db_dbse]): " . mysql_error()); if($osc[merge_method] == "FLUSH") { echo " * Flushing product/category tables in OSC database...\n"; mysql_query("DELETE FROM products"); mysql_query("DELETE FROM products_description"); mysql_query("DELETE FROM categories"); mysql_query("DELETE FROM categories_description"); mysql_query("DELETE FROM products_to_categories"); } /* Write IC DB contents to OSC product tables */ $n_products = count($products); $current = 0; $cols = 0; echo " * Performing product entry conversions ($n_products in queue):\n\n "; foreach($products as $product) { foreach($osc[field_map] as $osc_table => $fields) { /* Build SQL Queries */ /* set default query for tables... not reliant on ICDB data */ if($osc_table == "products") { $ins_f_part = "products_date_added, products_last_modified, products_date_available, products_status, "; $ins_v_part = "NOW(), NOW(), NOW(), '1', "; } else { $ins_f_part = "products_id, "; $ins_v_part = "'$osc_product_id',"; } $n_fields = count($fields); $cur_field = 0; foreach($fields as $icf => $oscf) { $ins_f_part .= $oscf; $ins_v_part .= "'" . addslashes($product[$icf]) . "'"; if($cur_field++ < $n_fields - 1) { $ins_f_part .= ", "; $ins_v_part .= ", "; } } $query = "INSERT INTO $osc_table ($ins_f_part) VALUES ($ins_v_part)"; mysql_query($query) or die("Cannot perform SQL query!"); if($osc_table == "products") { $osc_product_id = mysql_insert_id($osc_db_link); } } /* Build/Fetch Categories */ if($product[prod_group]) { $catid = make_osc_category($product[prod_group]); if($product[category]) { $catid = make_osc_category($product[category], $catid); } } /* Assign product to category */ $query = "INSERT INTO products_to_categories (products_id, categories_id) VALUES ('$osc_product_id', '$catid')"; mysql_query($query); echo "."; $cols++; if(++$current % 40 == 0 && $current != $n_products) { printf("| %0.1f%%\n ", ($current / $n_products) * 100); $cols = 0; } } for($i=0; $i<(40 - $cols); $i++) echo " "; echo "| 100%\n\n"; echo "\n * Closing MySQL connection...\n"; mysql_close($osc_db_link); echo " * Product Datbase Conversion Complete!\n\n"; echo "<--------------------------------------->\n\n"; ?> 1 THAT'S IT try saving it as *.php and running it somewhere, running a IIS (windows) and having a path to PHP. Or see the notes.. . www.php.net Link to comment Share on other sites More sharing options...
oglee Posted February 28, 2004 Share Posted February 28, 2004 were you able to get the script to work? i need to do the same! Jim Link to comment Share on other sites More sharing options...
Guest Posted February 28, 2004 Share Posted February 28, 2004 you need to modify the info for pointing to the osc database, username, etc . . . Link to comment Share on other sites More sharing options...
user99999999 Posted February 28, 2004 Share Posted February 28, 2004 I think you could look at the EasyPopulate import format and make a SQL query to pull your data in that format. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.