Migrate OsCommerce data to Magento catalog

There are times when you come across a situation where you have to migrate OsCommerce store’s data to Magento. I have been in such situations and used couple of migration tools that did not work.

So to tackle this problem, I created a custom script which helped me migrate OsCommerce to Magento seamlessly. I am sharing the steps that I took.

 Migrate Category.

  1. Create a migration folder on Magento root.
  2. Add below script in folder.
  3. Copy your image in media/import folder
  4. Now run the script using SSH.
<?php require_once '../app/Mage.php'; Mage::app(); /* Defult call add arg parent category = 0 and root category of you store  */ categortyRecarsion(0,2); function categortyRecarsion($pcat,$magentoP) { 	$dbhost = 'OS commarce host name'; 	$dbuser = 'USER NAME'; 	$dbpass = 'PASSWORD'; 	$conn = mysql_connect($dbhost, $dbuser, $dbpass); 	mysql_select_db('vanoutletdemo',$conn); 	$sql = "SELECT * FROM `categories` AS c INNER JOIN `categories_description` AS cd ON c.categories_id = cd.categories_id WHERE c.parent_id =".$pcat; 	$retval = mysql_query( $sql, $conn); 	while($row = mysql_fetch_array($retval, MYSQL_ASSOC)){         $cateID = createCategory($row['categories_name'],2,$magentoP,1,$row); 		echo $row['categories_name']; 		categortyRecarsion($row['categories_id'],$cateID); 	} } function createCategory($categoryName, $level=2, $pCatid='', $showInmenu=1,$catematadata) { 		$data = Mage::getModel('catalog/category')->getCollection()
            //->addAttributeToFilter('level', $level)
            ->addAttributeToFilter('parent_id', $pCatid)
            ->addAttributeToFilter('name', $categoryName);
		$catData = $data->getData();
		$catid = '';
		if (empty($catData)) {
            ## Add short name for flat page##
            $category = Mage::getModel('Catalog/category');
			$category->setName($categoryName);
            $category->setIsActive(1);
            $category->setIsAnchor(1);
			$category->getDescription($catematadata['categories_description']);
			$category->setMeta_title($catematadata['categories_meta_title']);
			$category->setMeta_keywords($catematadata['categories_meta_description']);
			$category->setMeta_description($catematadata['categories_meta_keywords']);
            $category->setInclude_in_menu($showInmenu);
			// Copy image for category 
			if($catematadata['categories_image']){
				copy(Mage::getBaseDir('media').DS.'import'.DS.$catematadata['categories_image'],Mage::getBaseDir('media').DS.'catalog'.DS."category".DS.$catematadata['categories_image']);
			}
            $parentCategory = Mage::getModel('catalog/category')->load($pCatid);
            $category->setPath($parentCategory->getPath());
            $category->save();
            $catid = $category->getId();
			if($catematadata['categories_image']){
				copy(Mage::getBaseDir('media').DS.'import'.DS.$catematadata['categories_image'],Mage::getBaseDir('media').DS.'catalog'.DS."category".DS.$catematadata['categories_image']);
					// Add Images by Insert query 3 = entity_type  45 = attribute_id for image //
				$insert = "INSERT INTO catalog_category_entity_varchar (entity_type_id, attribute_id,store_id,entity_id,value) VALUES (3,45,0,".$catid.",'"
				.$catematadata['categories_image']."')";
				$write = Mage::getSingleton( 'core/resource' )->getConnection( 'core_write' ); // To write to the database
				$write->query($insert);
			}
			if($catematadata['categories_image']){
				//echo $catid;exit;
			}
        } else {
            if(isset($catData[0]['entity_id']))
            $catid = $catData[0]['entity_id'];
        }
		return $catid;
}

Migrate Product

  1. Copy images in media/import folder.
  2. Create script which with covert OsCommerce  product into CSV which can we use in MAGMI to Import product (Contact me for this script)
  3. Now download MAGMI use it for import products.
  4. You can migrate product by this way very quickly (40K SKU in 20 min)

You can also import customers and orders using scrips. Feel free to contact me for any query.

One thought on “Migrate OsCommerce data to Magento catalog

  1. Abbas Arif May 13, 2016 / 3:26 am

    Do you have products, customers and orders import/export code? or atleast sample CSV for any?

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.