Skip to content

Instantly share code, notes, and snippets.

@wridgers
Created August 14, 2011 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wridgers/1144797 to your computer and use it in GitHub Desktop.
Save wridgers/1144797 to your computer and use it in GitHub Desktop.
Converting a CubeCart install to a PrestaShop install. Part 1.
<?php
function clean($in) {
// I used this function to rename things, since the conversation also required a name change.
$out = str_replace("Oldsite", "Newsite", $in);
return $out;
}
$source_database = 'dbname';
$source_server = 'dbserver';
$source_user = 'dbuser';
$source_pass = 'dbpass';
$source = mysql_connect( $source_server, $source_user, $source_pass );
mysql_select_db($source_database);
$result = mysql_query("SELECT cat_id, cat_father_id, cat_name, cat_desc, cat_metatitle, cat_metadesc, cat_metakeywords FROM `cubecart_category`;");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
//af_category
$af_category = "INSERT INTO `targetdatabase`.`af_category` (`id_category`, `id_parent`, `level_depth`, `active`) VALUES ('".$row[0]."', '".$row[1]."', '1', '1'); <br />";
//af_category_lang
$af_category_lang = "INSERT INTO `targetdatabase`.`af_category_lang` (`id_category`, `id_lang`, `name`, `description`, `link_rewrite`, `meta_title`, `meta_keywords`, `meta_description`)
VALUES ('".$row[0]."', '1', '".strip_tags($row[2])."', '".strip_tags($row[3])."', '".str_replace(' ', '-', strtolower($row[2]))."', '".strip_tags($row[4])."', '".strip_tags($row[5])."', '".strip_tags($row[6])."'); <br />";
$af_category_group = "INSERT INTO `targetdatabase`.`af_category_group` (`id_category`, `id_group`) VALUES ('".$row[0]."','1'); <br />";
echo clean($af_category);
echo clean($af_category_lang);
echo clean($af_category_group);
echo "<br /><br /><br />";
}
mysql_free_result($result);
$result = mysql_query("SELECT productId, disabled, productCode, description, image, price, name, cat_id, stock_level, prod_metatitle, prod_metadesc, prod_metakeywords FROM `cubecart_inventory`;");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$disable = $row[1];
$active = 1;
if ($disabled == 1) $active = 0;
// af_product
$af_product = "INSERT INTO `targetdatabase`.`af_product`
(`id_product`, `price`, `id_category_default`, `active`, `reference`) VALUES
('".$row[0]."', '".$row[5]."', '".$row[7]."', '".$active."', '".$row[2]."'); <br />";
// af_product_lang
$af_product_lang = "INSERT INTO `targetdatabase`.`af_product_lang` (`id_product`, `id_lang`, `description`,
`description_short`, `link_rewrite`, `meta_description`,
`meta_keywords`, `meta_title`, `name` ) VALUES
('".$row[0]."', '1', '".strip_tags($row[3])."',
'".strip_tags($row[3])."', '".str_replace(' ', '-', strtolower($row[6]))."', '".$row[10]."',
'".$row[11]."', '".$row[9]."', '".$row[6]."'); <br />";
// af_category_product
$af_category_product = "INSERT INTO `targetdatabase`.`af_category_product` (`id_category`, `id_product`)
VALUES ('".$row[7]."', '".$row[0]."'); <br />";
// af_image
$af_image = "INSERT INTO `targetdatabase`.`af_image` (`id_image`, `id_product`, `position`, `cover`)
VALUES ('".$row[0]."','".$row[0]."','1','1'); <br />";
// af_image_lang
$af_image_lang = "INSERT INTO `targetdatabase`.`af_image_lang` (`id_image`, `id_lang`, `legend`)
VALUES ('".$row[0]."','1','".$row[6]."'); <br />";
echo clean($af_product);
echo clean($af_product_lang);
echo clean($af_category_product);
echo clean($af_image);
echo clean($af_image_lang);
echo "<br/><br/><br/>";
}
mysql_free_result($result);
mysql_close($source);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment