 <?php
           $proxy = new SoapClient('http://localhost/api/soap/?wsdl');
      $sessionId = $proxy->login('user', 'password');
      $host ="localhost";
      $user = "db_user";
      $password = "db_password";

       $link = mysql_connect($host, $user, $password);
  		mysql_select_db("store");
  		
  		function getNewID($oldID){
  		   $q = "select new_id from mapping_table where id = $oldID";
	       $allD = mysql_query($q);
	       $row = mysql_fetch_assoc($allD);
	    	return $row["new_id"];	
  		}
  		
       function getAllParents($parentId){
	       $allParents = array();
	       $allParents[] = getNewID($parentId);
     	
       		 
       		while($parentId != 0){
       			$q = "select parent_id from zenccategories where categories_id = $parentId";
       			$allD = mysql_query($q);
       			if($row = mysql_fetch_assoc($allD)){
       				$parentId = $row["parent_id"];
       				if($parentId != 0){ 
       					$allParents[] = getNewID($parentId);
       				}
       			}		
       		}
       
       		return $allParents;
       }
		$rootCategoryID = 3;  
	  
		$baseURL = "/home/domain.com/html/media/import";  
	  $q = "delete from customer_mapping_table";
	  mysql_query($q);
	  $q = "select * from zenccustomers c inner join zencaddress_book z on z.customers_id = c.customers_id and c.customers_id  <> 47 ";
	  $result = mysql_query($q, $link);
	  $cnt = 1;
	  $customerIds = array();
	  while($row = mysql_fetch_assoc($result)){
	  	$customerData = array();
	  	 
 
		$newCustomer = array(
		    'firstname'  => $row['customers_firstname'],
		    'lastname'   => $row['customers_lastname'],
		    'created_at'   => date("Y-m-d H:i:s"),
		    'updated_at'   => date("Y-m-d H:i:s"),
		    'default_shipping'   => "274",
		    'group_id'   => "2",
		    'default_billing'   => "274",
		    'email'      => $row['customers_email_address'],
		    'password_hash'   => $row['customers_password'],
		    'store_id'   => 0,
		    'website_id' => 1
		);
		try {
		  	$newCustomerId = $proxy->call($sessionId, 'customer.create', array($newCustomer));
		  	$q = "insert into customer_mapping_table (id, new_id) values (" . $result["customers_id"] . ", $newCustomerId)";
		  	mysql_query($q);
		}catch(Exception $e){
			echo "\nException on " . $row["customers_firstname"] . " " ,  $row["customers_lastname"]; 
		}
	  //	break;
	  }
?>


