You are hereBlogs / willhall's blog / Migration of OsCommerce Products to Node Products

Migration of OsCommerce Products to Node Products


By willhall - Posted on 09 March 2010

The difficult thing that appears with moving the products using the migrate moduel appears to be the inability to put multiple tables into one table. To counteract this I ended up migrating all ot the Oscommerce product data into one database table and then sending the content over with the migrate module. The code ended up something like this although this is obviously editable dependant on what data you have in Oscommerce/want in Drupal:

Product aggregator to take products from Oscommerce and dump into a mysql file for insertion to Drupal Database.


<?php
$oscommerce_database = 'oscommerce';
mysql_connect('localhost', 'root', 'password') or die('Cannot connect to MySql');
mysql_select_db($oscommerce_database) or die('Cannot connect to database');

$sql = 'select * from products';
$query = mysql_query($sql);

echo "CREATE TABLE IF NOT EXISTS `products` (
`products_id` int(12) NOT NULL,
`products_model` varchar(25) default NULL,
`products_price` decimal(15,4) NOT NULL default '0.0000',
`products_weight` decimal(5,2) NOT NULL default '0.00',
`products_length` decimal(6,2) NOT NULL default '12.00',
`products_width` decimal(6,2) NOT NULL default '12.00',
`products_height` decimal(6,2) NOT NULL default '12.00',
`products_name` varchar(64) NOT NULL,
`products_tab` varchar(64) NOT NULL,
`products_description` text,
`short_desc` text,
PRIMARY KEY (`products_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=33 ;";

echo ''."INSERT INTO `products` (products_id, `products_model`, `products_price`, `products_weight`, `products_length`, `products_width`, `products_height`, `products_name`, `products_description`, `short_desc`) VALUES ".'';

while($result = mysql_fetch_assoc($query)){
$sql_desc = 'select * from products_description where products_id = '.$result['products_id'];
$product_query = mysql_query($sql_desc);
$product_desc = mysql_fetch_assoc($product_query);
$product_id = $result['products_id'];
$product_model = $result['products_model'];
$product_price = $result['products_price'];
$product_weight = $result['products_weight'];
$product_length = $result['products_length'];
$product_width = $result['products_width'];
$product_height = $result['products_height'];
$product_name = $product_desc['products_name'];
$product_description = $product_desc['products_description'];
$product_description = mysql_real_escape_string($product_description);
$product_description = htmlentities($product_description);
$product_st_desc = $product_desc['short_desc'];
$product_st_desc = mysql_real_escape_string($product_st_desc);
$product_st_desc = htmlentities($product_st_desc);
echo "($product_id, '$product_model', $product_price, $product_weight, $product_length, $product_width, $product_height, '$product_name', '$product_description', '$product_st_desc'),";
}

@willhallonline

  • exasperated at poor connections, may remove and reinstall everything! 10 hours 49 min ago
  • Government sticking to IE6 http://bit.ly/ceMrg9 "more cost effective in many cases to continue to use IE6" (what?!) 13 hours 17 min ago
  • still the mail server continues to frustrate 13 hours 24 min ago
  • feeling positive today, gonna destroy this damned mail server 18 hours 31 min ago
  • where are the open source business analysts who can help out with the actual running of companies, not just make a website for them 18 hours 32 min ago