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

  • does anyone know any good php courses I can send a beginner/intermediate developer on? 1 week 3 days ago
  • adobe gone... GIMP in... hmm maybe I'll just pass design to someone else to handle 1 week 4 days ago
  • removing adobe cs4... why? because I just don't use it 1 week 4 days ago
  • Working on my music site tonight. New release soon (its only been nearly 2 years) 2 weeks 8 hours ago
  • hmm, getting quite a bit of spam through my site today... how frustrating 2 weeks 14 hours ago