Migrate osCommerce to WooCommerce

In one of my earlier posts, I described the process I followed to migrate from osCommerce to WooCommerce. While this may have been a tedious job without this handy plugin, there were a few quirks I had to sort out. This plugin is not authored by me. I just made a few changes to address a few things. All credit to the original author.

First, the categories were displaying twice, after the import process was completed. Secondly, if you have more than one image for a product, the plugin does not import the additional images.

For the first issue, see my post here to resolve it.

For the second issue, you can simply download the updated version here. Here is the full text version of the file:

<?php
/*
Plugin Name: Woocommerce osCommerce Import
Plugin URI: http://www.advancedstyle.com/
Description: Import products, categories, customers and orders from osCommerce to Woocommerce
Author: David Barnes
Version: 1.1
Author URI: http://www.advancedstyle.com/
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

 function woocommerce_osc_submenu_page() {
 add_submenu_page( 'woocommerce', 'osCommerce Import', 'osCommerce Import', 'manage_options', 'woocommerce-osc-import', 'woocommerce_osc_submenu_page_callback' ); 
 }

 function woocommerce_osc_cartesian_product($a) {
 $result = array(array());
 foreach ($a as $k => $list) {
 $_tmp = array();
 foreach ($result as $result_item) {
 foreach ($list as $list_item) {
 $_tmp[] = array_merge($result_item, array($k => $list_item));
 }
 }
 $result = $_tmp;
 }
 return $result;
 }

 function woocommerce_osc_import_image($url){
 $attach_id = 0;
 $wp_upload_dir = wp_upload_dir();

 $filename = $wp_upload_dir['path'].'/'.sanitize_file_name(basename($url));

 if(file_exists($filename)){
 $url = $filename;
 }

 $enc_url = rtrim($_POST['store_url'],'/').'/image/'.rawurlencode(basename($url));

 //echo "Encoded URL ".$enc_url."<br>";

 if($f = @file_get_contents($enc_url)){
 file_put_contents($filename,$f);
 //echo "Writing to ".$filename."<br>";
 $wp_filetype = wp_check_filetype(basename($filename), null );

 $attachment = array(
 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), 
 'post_mime_type' => $wp_filetype['type'],
 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
 'post_content' => '',
 'post_status' => 'inherit'
 );
 $attach_id = wp_insert_attachment( $attachment, $filename, 37 );
 require_once(ABSPATH . 'wp-admin/includes/image.php');
 $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
 wp_update_attachment_metadata( $attach_id, $attach_data );
 }
 return $attach_id;
 }
 function woocommerce_osc_run_cats($parent=0, $parent_term_id=0){
 global $wpdb, $oscdb, $import_cat_counter;
 echo __LINE__."<br>";
 $categories = $oscdb->get_results("SELECT c.*, cd.* FROM categories c, categories_description cd WHERE c.categories_id=cd.categories_id AND cd.language_id=1 AND c.parent_id='".(int)$parent."'", ARRAY_A);
 if(!empty($categories)){
 foreach($categories as $category){
 $term = term_exists($category['categories_name'], 'product_cat', (int)$parent_term_id); // array is returned if taxonomy is given
 echo __LINE__."<br>";
 if ((int)$term['term_id'] == 0) {
 $term = wp_insert_term(
 $category['categories_name'], // the term 
 'product_cat', // the taxonomy
 array(
 //'description'=> $category['categories_id'],
 'parent'=> $parent_term_id
 )
 );
 delete_option('product_cat_children'); // clear the cache

 $attach_id = 0;
 if($category['categories_image'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.urlencode($category['categories_image']);
 $attach_id = woocommerce_osc_import_image($url);
 }
 //add_woocommerce_term_meta($term['term_id'], 'order',$category['sort_order']);
 add_woocommerce_term_meta($term['term_id'], 'display_type','');
 add_woocommerce_term_meta($term['term_id'], 'thumbnail_id',(int)$attach_id);
 add_woocommerce_term_meta($term['term_id'], 'osc_id',$category['categories_id']);
 woocommerce_osc_run_cats($category['categories_id'], $term['term_id']);
 $import_cat_counter ++;
 }else{
 woocommerce_osc_run_cats($category['categories_id'], $term['term_id']);
 echo __LINE__."<br>";
 }
 }
 }
 }

 function woocommerce_osc_submenu_page_callback() {
 global $wpdb, $oscdb, $import_cat_counter, $import_prod_counter;
 if(!empty($_POST)){
 $oscdb = new wpdb($_POST['store_user'],$_POST['store_pass'],$_POST['store_dbname'],$_POST['store_host']);
 if($oscdb->ready){
 echo '<p>Starting...<em>(If the page stops loading or shows a timeout error, then just refresh the page and the importer will continue where it left off. If you are using a shared server and are importing a lot of products you may need to refresh several times)</p>';
 // Do customer import
 if($_POST['dtype']['customers'] == 1){
 $country_data = $oscdb->get_results("SELECT * FROM countries", ARRAY_A);
 $countries_id = array();
 foreach($country_data as $cdata){
 $countries_id[$cdata['countries_id']] = $cdata;
 }
 $zones = array();
 $zone_data = $oscdb->get_results("SELECT zone_id, zone_code FROM zones", ARRAY_A);
 foreach($zone_data as $z){
 $zones[$z['zone_id']] = $z['zone_code'];
 }

 if($customers = $oscdb->get_results("SELECT c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_country_id, ab.entry_lastname, ab.entry_firstname, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_state, ab.entry_zone_id FROM customers c, address_book ab WHERE c.customers_id=ab.customers_id AND c.customers_default_address_id=ab.address_book_id", ARRAY_A)){
 foreach($customers as $customer){
 //echo "Importing Customer :".$customer['customers_firstname'].$customer['customers_lastname']."<br>";
 if ( !email_exists($customer['customers_email_address'])) {
 $original = strtolower(preg_replace("/[^A-Za-z0-9]/", '', $customer['customers_firstname'].$customer['customers_lastname']));
 $user_name = $original;

 $i = 1;
 while($user_id = username_exists( $user_name )){
 $user_name = $original.$i;
 $i++;
 }

 $random_password = wp_generate_password();
 $user_id = wp_create_user( $user_name, $random_password, $customer['customers_email_address'] );

 $data = array('first_name' => $customer['customers_firstname'],
 'last_name' => $customer['customers_lastname'],
 'billing_country' => $countries_id[$customer['entry_country_id']]['countries_iso_code_2'],
 'billing_first_name' => $customer['entry_firstname'],
 'billing_last_name' => $customer['entry_lastname'],
 'billing_address_1' => $customer['entry_street_address'],
 'billing_address_2' => $customer['entry_suburb'],
 'billing_city' => $customer['entry_city'],
 'billing_state' => ($customer['entry_state'] != '' ? $customer['entry_state'] : $zones[$customer['entry_zone_id']]),
 'billing_postcode' => $customer['entry_postcode'],
 'billing_email' => $customer['customers_email_address'],
 'billing_phone' => $customer['customers_telephone'],
 'shipping_country' => $countries_id[$customer['entry_country_id']]['countries_iso_code_2'],
 'shipping_first_name' => $customer['entry_firstname'],
 'shipping_last_name' => $customer['entry_lastname'],
 'shipping_address_1' => $customer['entry_street_address'],
 'shipping_address_2' => $customer['entry_suburb'],
 'shipping_city' => $customer['entry_city'],
 'shipping_state' => ($customer['entry_state'] != '' ? $customer['entry_state'] : $zones[$customer['entry_zone_id']]),
 'shipping_postcode' => $customer['entry_postcode'],
 'osc_id' => $customer['customers_id']);
 foreach($data as $k => $v){
 update_user_meta( $user_id, $k, $v);
 }

 wp_update_user(array('ID' => $user_id, 'role' => 'customer'));

 $import_customer_counter++;
 }
 }
 }
 }
 //echo __LINE__;
 if($_POST['dtype']['products'] == 1){

 //woocommerce_osc_run_cats();
 //echo __LINE__;
 // Get all categories by OSC cat ID
 $categories = array();
 $terms = get_terms('product_cat',array('hide_empty' => 0));
 foreach ( $terms as $term ) {
 $o = get_woocommerce_term_meta($term->term_id,'osc_id',true);
 $categories[$o] = (int)$term->term_id;
 }
 //echo __LINE__;

 // Import the products
 if($products = $oscdb->get_results("SELECT p.*, pd.*, p2c.categories_id FROM products p, products_description pd, products_to_categories p2c WHERE p.products_id=pd.products_id AND pd.language_id=1 AND p.products_id=p2c.products_id", ARRAY_A)){
 foreach($products as $product){

 $existing_product = get_posts(array('post_type' => 'product','posts_per_page' => 1,'post_status' => 'any',
 'meta_query' => array(
 array(
 'key' => 'osc_id',
 'value' => $product['products_id'],
 )
 )));
 if(empty($existing_product)){
 $product_id = wp_insert_post(array(
 'post_title' => $product['products_name'],
 'post_content' => $product['products_description'],
 'post_status' => 'publish',
 'post_type' => 'product',
 'post_author' => 1
 ));
 echo "Importing Product ".$product['products_name']."<br>";
 update_post_meta($product_id, 'osc_id', $product['products_id']);
 wp_set_object_terms($product_id, 'simple', 'product_type');
 wp_set_object_terms($product_id, $categories[$product['categories_id']], 'product_cat');
 update_post_meta($product_id, '_sku', $product['products_model']);
 update_post_meta($product_id, '_regular_price', $product['products_price']);
 update_post_meta($product_id, '_price', $product['products_price']);
 update_post_meta($product_id, '_visibility', 'visible' );
 update_post_meta($product_id, '_stock_status', ($product['products_status'] ? 'instock' : 'outofstock'));
 update_post_meta($product_id, '_manage_stock', '1' );
 update_post_meta($product_id, '_stock', $product['products_quantity']);

 if($special = $oscdb->get_row("SELECT specials_new_products_price, expires_date FROM specials WHERE status=1 AND products_id='".$product_id."' LIMIT 1", ARRAY_A)){
 update_post_meta($product_id, '_sale_price', $special['specials_new_products_price']);
 $special['expires_date'] = strtotime($special['expires_date']);
 if($special['expires_date'] > time()){
 update_post_meta($product_id, '_sale_price_dates_to', date("Y-m-d",$special['expires_date']));
 update_post_meta($product_id, '_sale_price_dates_from', date("Y-m-d"));
 }
 }

 $attach_id = 0;
 if($product['products_image'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_image'];
 $attach_id = woocommerce_osc_import_image($url);
 }
 set_post_thumbnail($product_id, $attach_id);

 $subimages = array();

 reset($subimages);
 // BEGIN : Multiple Images
 if ($product['products_subimage1'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_subimage1'];
 //echo "Found SubImage 1 : ".$url;
 $attach_id = woocommerce_osc_import_image($url);
 $subimages[0] = $attach_id; 
 }

 if ($product['products_subimage2'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_subimage2'];
 //echo "Found SubImage 2 : ".$url;
 $attach_id = woocommerce_osc_import_image($url);
 $subimages[1] = $attach_id; 
 } 
 if ($product['products_subimage3'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_subimage3'];
 //echo "Found SubImage 3 : ".$url;
 $attach_id = woocommerce_osc_import_image($url);
 $subimages[2] = $attach_id; 
 } 
 if ($product['products_subimage4'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_subimage4'];
 //echo "Found SubImage 4 : ".$url;
 $attach_id = woocommerce_osc_import_image($url);
 $subimages[3] = $attach_id; 
 } 
 if ($product['products_subimage5'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_subimage5'];
 //echo "Found SubImage 5 : ".$url;
 $attach_id = woocommerce_osc_import_image($url);
 $subimages[4] = $attach_id; 
 } 
 if ($product['products_subimage6'] != ''){
 $url = rtrim($_POST['store_url'],'/').'/image/'.$product['products_subimage6'];
 //echo "Found SubImage 6 : ".$url;
 $attach_id = woocommerce_osc_import_image($url);
 $subimages[5] = $attach_id; 
 } 

 //$subimages = array_filter($subimages);

 if (count($subimages) > 0)
 {
 if (count($subimages) == 1)
 {
 echo "Inserting Single Subimage ".$subimages[0]."<br>";
 update_post_meta( $product_id, '_product_image_gallery', $subimages[0] );
 }
 else 
 { 
 //print_r($subimages);
 echo "Inserting Multiple Subimages ".implode( ",", $subimages )."<br>";
 update_post_meta( $product_id, '_product_image_gallery', implode( ",", $subimages ) );
 }
 }
 else
 {
 echo "No Subimages Found";
 //print_r($subimages);
 //print_r($product);
 }

 unset($subimages);

 // END : Multiple Images

 // Handle attributes
 if($attributes = $oscdb->get_results("SELECT po.products_options_name, pov.products_options_values_name FROM products_attributes pa, products_options po, products_options_values pov WHERE pa.products_id='".$product['products_id']."' AND pov.products_options_values_id = pa.options_values_id AND pov.language_id=po.language_id AND po.language_id=1 AND pa.options_id=products_options_id", ARRAY_A)){
 wp_set_object_terms($product_id, 'variable', 'product_type');

 $attrib_array = array();
 $attrib_combo = array();
 $max_price = $product['products_price'];
 $min_price = $product['products_price'];
 foreach($attributes as $attribute){
 $slug = sanitize_title($attribute['products_options_name']);
 $attrib_array[$slug] = array('name' => $attribute['products_options_name'],
 'value' => ltrim($attrib_array[$slug]['value'].' | '.$attribute['products_options_values_name'],' | '),
 'position' => 0,
 'is_visible' => 1,
 'is_variation' => 1,
 'is_taxonomy' => 0);
 $attrib_combo[$slug][] = array($attribute['products_options_values_name'], ($attribute['price_prefix'] == '-' ? '-' : '').$attribute['options_values_price']);
 }
 // Now it gets tricky...
 $combos = woocommerce_osc_cartesian_product($attrib_combo);
 foreach($combos as $combo){
 $variation_id = wp_insert_post(array(
 'post_title' => 'Product '.$product_id.' Variation',
 'post_content' => '',
 'post_status' => 'publish',
 'post_type' => 'product_variation',
 'post_author' => 1,
 'post_parent' => $product_id
 ));

 $opt_price = $product['products_price'];

 $special_price = $special['specials_new_products_price'];

 foreach($combo as $k => $v){
 update_post_meta($variation_id, 'attribute_'.$k, $v[0]);
 $opt_price += $v[1];
 $special_price += $v[1];
 }
 update_post_meta($variation_id, '_sku', $product['products_model']);
 update_post_meta($variation_id, '_regular_price', $opt_price);
 update_post_meta($variation_id, '_price', $opt_price);
 update_post_meta($variation_id, '_thumbnail_id', 0);
 update_post_meta($variation_id, '_stock', $product['products_quantity'] );
 if($special){
 update_post_meta($variation_id, '_sale_price', $special_price);
 if($special['expires_date'] > time()){
 update_post_meta($variation_id, '_sale_price_dates_to', date("Y-m-d",$special['expires_date']));
 update_post_meta($variation_id, '_sale_price_dates_from', date("Y-m-d"));
 }
 }
 if($opt_price > $max_price){
 $max_price = $opt_price;
 }
 if($opt_price < $min_price){
 $min_price = $opt_price;
 }
 }

 update_post_meta($product_id, '_product_attributes', $attrib_array);
 update_post_meta($product_id, '_max_variation_regular_price',$max_price);
 update_post_meta($product_id, '_min_variation_regular_price', $min_price);
 update_post_meta($product_id, '_max_variation_price', $max_price);
 update_post_meta($product_id, '_min_variation_price', $min_price);
 }

 }
 }
 }
 }

 if($_POST['dtype']['orders'] == 1){
 $customers = $wpdb->get_results("SELECT ID FROM $wpdb->users", ARRAY_A);
 $customer_id = array();
 foreach($customers as $c){
 $osc_id = get_user_meta($c['ID'],'osc_id',true);
 $customer_id[$osc_id] = $c['ID'];
 }

 $product_id = array();
 $products_query = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type='product'", ARRAY_A);
 foreach($products_query as $p){
 $osc_id = get_post_meta($p['ID'],'osc_id',true);
 $product_id[$osc_id] = $p['ID'];
 }

 $country_data = $oscdb->get_results("SELECT * FROM countries", ARRAY_A);
 $countries_name = array();
 foreach($country_data as $cdata){
 $countries_name[$cdata['countries_name']] = $cdata;
 }

 if($orders = $oscdb->get_results("SELECT * FROM orders ORDER BY orders_id", ARRAY_A)){
 foreach($orders as $order){
 $existing_order = get_posts(array('post_type' => 'shop_order','posts_per_page' => 1,'post_status' => 'any',
 'meta_query' => array(
 array(
 'key' => 'osc_id',
 'value' => $order['orders_id'],
 )
 )));
 if(empty($existing_order)){
 $totals = array();
 if($total_query = $oscdb->get_results("SELECT * FROM orders_total WHERE orders_id='".$order['orders_id']."'", ARRAY_A)){
 foreach($total_query as $t){
 $totals[$t['class']] = $t;
 }
 }

 $order_key = 'order_'.wp_generate_password(13);

 $data = array('post_type' => 'shop_order',
 'post_date' => $order['date_purchased'],
 'post_author' => $customer_id[$order['customers_id']],
 'post_password' => $order_key,
 'post_title' => 'Order &ndash; '.date("M d, Y @ h:i A",strtotime($order['date_purchased'])),
 'post_status' => 'publish'
 );
 $order_id = wp_insert_post($data);

 $billing_namebits = explode(' ',$order['billing_name']);
 $billing_firstname = $billing_namebits[0];
 $billing_lastname = trim(str_replace($billing_namebits[0],'',$order['billing_name']));

 $shipping_namebits = explode(' ',$order['delivery_name']);
 $shipping_firstname = $shipping_namebits[0];
 $shipping_lastname = trim(str_replace($shipping_namebits[0],'',$order['delivery_name']));

 $meta_data = array('_billing_address_1' => $order['billing_street_address'],
 '_billing_address_2' => $order['billing_suburb'],
 '_wpas_done_all' => 1,
 '_billing_country' => $countries_name[$order['billing_country']]['countries_iso_code_2'],
 '_billing_first_name' => $billing_firstname,
 '_billing_last_name' => $billing_lastname,
 '_billing_company' => $order['billing_company'],
 '_billing_city' => $order['billing_city'],
 '_billing_state' => $order['billing_state'],
 '_billing_postcode' => $order['billing_postcode'],
 '_billing_phone' => $order['customers_telephone'],
 '_billing_email' => $order['customers_email_address'],
 '_shipping_country' => $countries_name[$order['delivery_country']]['countries_iso_code_2'],
 '_shipping_first_name' => $shipping_firstname,
 '_shipping_last_name' => $shipping_lastname,
 '_shipping_company' => $order['delivery_company'],
 '_shipping_address_1' => $order['delivery_street_address'],
 '_shipping_address_2' => $order['delivery_suburb'],
 '_shipping_city' => $order['delivery_city'],
 '_shipping_state' => $order['delivery_state'],
 '_shipping_postcode' => $order['delivery_postcode'],
 '_shipping_method_title' => $totals['ot_shipping']['title'],
 '_payment_method_title' => $order['payment_method'],
 '_order_shipping' => $totals['ot_shipping']['value'],
 '_order_discount' => $totals['ot_coupon']['value'] + $totals['ot_discount']['value'],
 '_order_tax' => $totals['ot_tax']['value'],
 '_order_shipping_tax' => 0,
 '_order_total' => $totals['ot_total']['value'],
 '_order_key' => $order_key,
 '_customer_user' => $customer_id[$order['customers_id']],
 '_order_currency' => $order['currency'],
 '_prices_include_tax' => 'no',
 'osc_id' => $order['orders_id']);
 foreach($meta_data as $k => $v){
 update_post_meta($order_id, $k, $v);
 }

 $order_import_counter++;

 if($order_products = $oscdb->get_results("SELECT * FROM orders_products WHERE orders_id='".$order['orders_id']."'", ARRAY_A)){
 foreach($order_products as $product){
 $item_id = woocommerce_add_order_item( $order_id, array(
 'order_item_name' => $product['products_name'],
 'order_item_type' => 'line_item'
 ) );

 if ( $item_id ) {
 $item_meta = array('_qty' => $product['products_quantity'],
 '_product_id' => $product_id[$product['products_id']],
 '_line_subtotal' => $product['final_price'] * $product['products_quantity'],
 '_line_total' => $product['final_price'] * $product['products_quantity']);
 foreach($item_meta as $k=>$v){
 woocommerce_add_order_item_meta($item_id,$k,$v);
 }
 } 

 }
 }
 }
 }
 }
 }

 $success = true;
 }else{
 echo '<p class="notice">Could not connect to the osCommerce database</p>';
 }
 }
 if($success){
 echo '<h3>The oscommerce data was successfully imported</h3>';
 if($_POST['dtype']['customers'] == 1){
 echo '<p><strong>Customers Imported: '.$import_customer_counter.'</p>';
 }
 if($_POST['dtype']['orders'] == 1){
 echo '<p><strong>Orders Imported: '.$order_import_counter.'</p>';
 }
 if($_POST['dtype']['products'] == 1){
 echo '<p><strong>Categories Imported: '.$import_cat_counter.'</p>';
 echo '<p><strong>Products Imported: '.$import_prod_counter.'</p>';
 }
 }else{
 ?>
 <form action="<?php echo $_SERVER['REQUEST_URI'];?>" method="post">
 <h3>Import data from osCommerce</h3>
 <p>Enter your oscommerce database information (you will need remote access to your oscommerce database)</p>
 <p><label>osCommerce store URL: <input type="text" name="store_url" value="<?php echo $_POST['store_url'];?>"></label></p>
 <p><label>osCommerce Database Host: <input type="text" name="store_host" value="localhost"></label></p>
 <p><label>osCommerce Database User: <input type="text" name="store_user" value="<?php echo $_POST['store_user'];?>"></label></p>
 <p><label>osCommerce Database Password: <input type="text" name="store_pass" value="<?php echo $_POST['store_pass'];?>"></label></p>
 <p><label>osCommerce Database Name: <input type="text" name="store_dbname" value="<?php echo $_POST['store_dbname'];?>"></label></p>
 <p>Data to Import:<br>
 <label><input type="checkbox" name="dtype[customers]" value="1"> Customers (passwords will not be transferred)</label><br>
 <label><input type="checkbox" name="dtype[orders]" value="1"> Orders</label><br>
 <label><input type="checkbox" name="dtype[products]" value="1"> Categories/Products</label>
 </p>
 <p><input type="submit" value="Import Data" class="button button-primary button-large"></p>
 </form>
 <?php
 }
 }
 add_action('admin_menu', 'woocommerce_osc_submenu_page',99);
}
?>

Posted

in

,

by

Comments

29 responses to “Migrate osCommerce to WooCommerce”

  1. Siva Avatar
    Siva

    Hi,

    You are awesome, working great. you splendid. but i have one query, my categories are not updated can you please clarify ?

    Thanks.

    1. Amit Ramani Avatar

      Hi Siva
      What is the URL for your site? Did your categories get imported at all?

  2. Siva Avatar
    Siva

    Hi Amit,

    Thanks for your prompt reply. sorry for my delay.
    I have followed your instructions, all the orders, customers and products were successfully imported, but not only the categories. while go and check my woo commerce category section its empty. please let me know your thoughts.

    Thanks.

  3. miki Avatar
    miki

    Hello,

    Found this thread and as I have also problem with double categories after import, tried to replace current php file with provided code. But then all already imported categories disappeared from the site and if I try to access categories or plugin in admin, getting error: Parse error: syntax error, unexpected ‘}’ in myurl/plugins/woocommerce-oscommerce-import/woocommerce-osc-import.php on line 11 . Any ideas how to solve that?

    1. Amit Ramani Avatar

      Hi @miky
      Please make sure your PHP code has the correct opening and closing PHP tags. The error you are receiving is from un-balanced and/or missing tags.

  4. Brixton Avatar
    Brixton

    Hello Amit,
    Just wanted to say thanks. I was having trouble importing products (couldn’t get a single one). I switched to your script and it worked. Thanks again for posting this article. It was a huge help. Cheers!

    1. Amit Ramani Avatar

      Hello Brixton
      Glad to hear the script was useful for you!

  5. wayand Avatar
    wayand

    hi, i am using wp 4.5.2 with wooCommerce 2.5.5

    and trying to import from oscommerce, i am getting success message, but nothing is imported, what can be issue?

    wayand.

    1. Amit Ramani Avatar

      Can you check your error log to see if there are any PHP errors? Did you enter the database details correctly? There could be a lot of reasons for failure, hard to debug without a log.

      1. Wayand Bahramzy Avatar
        Wayand Bahramzy

        thank you for you reply,
        I did enter correct database informations, otherwise it will display an error.

        i just reset everything (caches, session etc from woocommerce settings) and try again, getting same success message:

        The oscommerce data was successfully imported
        Customers Imported:
        Orders Imported:
        Categories Imported:
        Products Imported:

  6. Wayand Bahramzy Avatar
    Wayand Bahramzy

    hmm, i just found out that i have prefix on my tables, how can i implement prefix to the script easily.

    1. Wayand Bahramzy Avatar
      Wayand Bahramzy

      I added the prefix to all databases select queries. and it was able to add all custommers, but still no Categories or orders.

      i get this:(
      The oscommerce data was successfully imported

      Notice: Undefined variable: import_customer_counter in /www/woo/wp-content/plugins/woocommerce-oscommerce-import/woocommerce-osc-import.php on line 498
      Customers Imported:

      Notice: Undefined variable: order_import_counter in /www/woo/wp-content/plugins/woocommerce-oscommerce-import/woocommerce-osc-import.php on line 501
      Orders Imported:

      Categories Imported:

      Products Imported:

  7. Rory Avatar
    Rory

    Hi,

    At https://woocommerce.com/products/oscommerce-to-woocommerce/ it says that the plugin is limited to 10,000 products. How/why is that? I’d like to transfer more than this accross. Do you know how to get around this problem?

    Many thanks,

    Rory

    1. Amit Ramani Avatar

      Hi Rory
      I am not sure why the limit it set to 10000 products. I am guessing because PHP script timeout is typically set to 30 seconds for shared hosting environments. How many products do you have?
      In my case, I normally change the database query to bring in 50 products at a time anyway. You can easily do that by appending “LIMIT 50 OFFSET x” to the database query related to the Products. The “x” in this case would change from 0 to 49 to 99 to 149 and so on.
      Hope that helps.

      1. Rory Avatar
        Rory

        Hi Amit,

        Thank you so much for your response, that certainly sounds worth a try. We are looking at just under 35,000 products.

        I’ve noticed that in line 109 it says:
        echo ‘Starting…(If the page stops loading or shows a timeout error, then just refresh the page and the importer will continue where it left off. If you are using a shared server and are importing a lot of products you may need to refresh several times)’;

        Perhaps it’s just a case of refreshing the page many times?

        I really appreciate the help – I’ll let you know if it works :-).

        Thanks,

        Rory

  8. Rory Avatar
    Rory

    Hi Amit,

    I’ve tried using the importer. It doesn’t seem to take any of our customers, orders or page information accross. It’s also only taken our categories through and none of our products. When I try adding catergories/products I get the following error:

    Fatal error: Cannot use object of type WP_Error as array in /home/fish4partscom/public_html/wp-content/plugins/woocommerce-oscommerce-import/woocommerce-osc-import.php on line 89

    When I refresh the page we have to insert all of the database information again and it doesn’t add any more categories or products.

    Any help or tips would be greatly appreciated!

    Many thanks,

    Rory

    1. Amit Ramani Avatar

      Hi Rory
      Without the debug log, it is hard to tell why it is not importing the Customers and Orders. First off, can you try importing just Customers (leave the Customers check box ON and turn the rest OFF).

      Also, I do not know what is on Line 89 (where you are receiving the error) of the file you are working with. Maybe you can paste that line here as well?

      1. Rory Avatar
        Rory

        Hi Amit,

        I’ve tried importing each of the individually, but it doesn’t work.

        Line 89: add_woocommerce_term_meta($term[‘term_id’], ‘order’,$category[‘sort_order’]);

        In case this helps, Lines 68 to 94 read:
        $categories = $oscdb->get_results(“SELECT c.*, cd.* FROM categories c, categories_description cd WHERE c.categories_id=cd.categories_id AND cd.language_id=1 AND c.parent_id=’”.(int)$parent.”‘”, ARRAY_A);

        if(!empty($categories)){

        foreach($categories as $category){

        if(!is_wp_error($category)){

        $term = term_exists($category[‘categories_name’], ‘product_cat’, (int)$parent_term_id); // array is returned if taxonomy is given

        if ((int)$term[‘term_id’] == 0) {

        $term = wp_insert_term(

        $category[‘categories_name’], // the term

        ‘product_cat’, // the taxonomy

        array(

        //’description’=> $category[‘categories_id’],

        ‘parent’=> $parent_term_id

        )

        );

        delete_option(‘product_cat_children’); // clear the cache

        $attach_id = 0;

        if($category[‘categories_image’] != ”){

        $url = rtrim($_POST[‘store_url’],’/’).’/images/’.urlencode($category[‘categories_image’]);

        $attach_id = woocommerce_osc_import_image($url);

        }

        add_woocommerce_term_meta($term[‘term_id’], ‘order’,$category[‘sort_order’]);

        add_woocommerce_term_meta($term[‘term_id’], ‘display_type’,”);

        add_woocommerce_term_meta($term[‘term_id’], ‘thumbnail_id’,(int)$attach_id);

        add_woocommerce_term_meta($term[‘term_id’], ‘osc_id’,$category[‘categories_id’]);

        woocommerce_osc_run_cats($category[‘categories_id’], $term[‘term_id’]);

        $import_cat_counter ++;

        Many thanks,

        Rory

        1. Amit Ramani Avatar

          Hi Rory
          Sorry for the late response. At this point, I am not sure what is causing the failure in your setup. I know this sounds obvious, but you do have WooCommerce plugin installed and activated?
          Can you enable WP_DEBUG in wp-config.php and collect a full error log?
          I am using the same script(Woocommerce Oscommerce import) currently on my localhost environment and it works fine without any issues. I have a feeling something crucial is missing from your setup?

          Have you looked at your database via phpMyAdmin? Sorry but at this point, I am unable to offer you any more suggestions without working on your setup. If you want to reach me via email, I can help further. Are you on a localhost environment or a staging environment so we can run it over there?

          1. Rory Avatar
            Rory

            Hi Amit,

            Thanks, I’m going to enable the WP_DEBUG. I’ll look into phpMyAdmin too. The WooCommerce plugin is installed and activated, but I’ll try what you’ve suggested and get back to you. We are currently not on a localhost or staging environment, but I could get one set up.

            I’ve very new to web development so it could take me a little while before I’ve got all of these things sorted.

            I appreciate your help very much!

            Thanks,

            Rory

          2. Rory Avatar
            Rory

            Hi Amit,

            I enabled the WP_debug, but there’s no log file being generated. I first tried this by adding
            define(‘WP_DEBUG_LOG’, true);
            define(‘WP_DEBUG_DISPLAY’, true);
            to the wp-config.php file and then by installing the debug plugin.

            I’m still not geting a debug.log file being generated in the /wp-content/ folder. I still get the:

            “Fatal error: Cannot use object of type WP_Error as array in /home/fish4partscom/public_html/wp-content/plugins/woocommerce-oscommerce-import/woocommerce-osc-import.php on line 89”

            But no debug.log.

            Any idea what I’m doing wrong?

            Thanks,

            Rory

          3. Amit Ramani Avatar

            Hi Rory
            I am not sure why the debug setup is not working for you. Unfortunately, I can not help you any more from remote. I can offer to take a look at your specific site if you want to share your login details with me.
            It is puzzling why the script is throwing an error for your specific setup. I am working on it as well for importing a site with 5000+ products and so far it is working well. I have not imported all the products yet (I am doing 50 at a time), but it does import Customers, Orders, Categories/Products quite smoothly. I have also added the functionality to import Manufacturers from oscommerce to WooCommerce Brands.
            Let me know if I can help further.

    2. Francisco Avatar
      Francisco

      Hi, I have the same error! Could you find the solution?

  9. Marco Avatar
    Marco

    Hi, I’ve tried to make the plugin work but without success, I’ve configured the plugin but every time I get “Could not connect to the osCommerce database”, I can’t understand why, though.
    Any tips to get it working?

    Best regards,
    keep up the good work

    1. Amit Ramani Avatar

      If you are receiving that error, it usually means one or more of the following:

      • Are you entering the correct value for the “oscommerce Database Host”?
      • Are you entering the correct “Database User”, “Database Password” and “Database Name”?

      If any one of those items is not correct, you will receive that error. For my purposes, I usually use this plugin on my local machine. So I use “localhost” for “oscommerce Database host”.

      1. Marco Avatar
        Marco

        Resetting WordPress seems to have solved the issue.
        And I’ve noticed that on the GitHub of the original developer there’s a version of the plugin (1.2.2) that solves the issues of the older versions.

        https://github.com/alexwing/woocommerce-oscommerce-import

  10. waheed Avatar

    very great splended work.
    I have one query. I have downloaded all the images to local server and setup a woocomerce site in localserver. the oscommerce images are store in database some are included directory name while some have space in their name. therefore some images were not added in woo products. after removing urlencode() from product image field now i can save images with directory included in product name inside database . but still now i m not able to save images which have space in their name in database for products. suppose an image name “the test image.jpg” is not being save.

    it will be great if you could assist me on this asap.
    thanks in advance.

    1. Amit Ramani Avatar

      You will have to check the image handling code to process these images. I do not know offhand how to make those changes.

  11. kevinrichesin.wordpress.com Avatar

    What’s up friends, its wonderful post regarding educationand entirely explained, keep it up all the time.

Leave a Reply

Your email address will not be published. Required fields are marked *