Skip to content

Instantly share code, notes, and snippets.

@epson121
Last active August 29, 2015 14:12
Show Gist options
  • Save epson121/00a5d1601a2744891894 to your computer and use it in GitHub Desktop.
Save epson121/00a5d1601a2744891894 to your computer and use it in GitHub Desktop.
xcart_to_magento_customers.php
<?php
$magento_header = array("website","email","group_id","disable_auto_group_change","firstname","lastname","password_hash","billing_prefix","billing_firstname","billing_middlename","billing_lastname","billing_suffix","billing_street_full","billing_street1","billing_street2","billing_street3","billing_street4","billing_street5","billing_street6","billing_street7","billing_street8","billing_city","billing_region","billing_country","billing_postcode","billing_telephone","billing_company","billing_fax","shipping_prefix","shipping_firstname","shipping_middlename","shipping_lastname","shipping_suffix","shipping_street_full","shipping_street1","shipping_street2","shipping_street3","shipping_street4","shipping_street5","shipping_street6","shipping_street7","shipping_street8","shipping_city","shipping_region","shipping_country","shipping_postcode","shipping_telephone","shipping_company","shipping_fax","created_in","is_subscribed","group","prefix","middlename","suffix","taxvat");
// Array
// (
// [0] => login
// [1] => usertype
// [2] => membership
// [3] => password
// [4] => password_hint
// [5] => password_hint_answer
// [6] => b_address
// [7] => b_city
// [8] => b_county
// [9] => b_state
// [10] => b_country
// [11] => b_zipcode
// [12] => title
// [13] => firstname
// [14] => lastname
// [15] => company
// [16] => s_address
// [17] => s_city
// [18] => s_county
// [19] => s_state
// [20] => s_country
// [21] => s_zipcode
// [22] => email
// [23] => phone
// [24] => fax
// [25] => url
// [26] => card_name
// [27] => card_type
// [28] => card_number
// [29] => card_expire
// [30] => card_cvv2
// [31] => last_login
// [32] => first_login
// [33] => status
// [34] => referer
// [35] => pending_membership
// [36] => ssn
// [37] => language
// [38] => cart
// [39] => change_password
// [40] => parent
// [41] => pending_plan_id
// [42] => card_numbers
// [43] => use_cards_archive
// )
$file = fopen("xcart_customers.csv","r");
$emails_list = array();
$result = array($magento_header);
$counter = 1;
while(! feof($file)) {
$row = fgetcsv($file);
if ($counter == 1) {
$counter = 2;
echo "OK";
continue;
}
if ($counter % 100 == 0)
echo $counter . "\n";
//check if email is unique
if (in_array(trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[22])), $emails_list))
continue;
else
$emails_list[] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[22]));
$magento_row = array();
$magento_row['website'] = 'base';
// email field
$magento_row["email"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[22]));
$magento_row["group_id"] = 'General';
$magento_row["disable_auto_group_change"] = 0;
//first name
$magento_row["firstname"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[13]));
$magento_row["lastname"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[14]));
$magento_row["password_hash"] = "";
$magento_row["billing_prefix"] = "";
$magento_row["billing_firstname"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[13]));
$magento_row["billing_middlename"] = "";
$magento_row["billing_lastname"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[14]));
$magento_row["billing_suffix"] = "";
//b_address
$magento_row["billing_street_full"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[6]));
$magento_row["billing_street1"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[6]));
$magento_row["billing_street2"] = "";
$magento_row["billing_street3"] = "";
$magento_row["billing_street4"] = "";
$magento_row["billing_street5"] = "";
$magento_row["billing_street6"] = "";
$magento_row["billing_street7"] = "";
$magento_row["billing_street8"] = "";
$magento_row["billing_city"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[17]));
// b_state
$magento_row["billing_region"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[9]));
$magento_row["billing_country"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[10]));
$magento_row["billing_postcode"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[11]));
$magento_row["billing_telephone"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[23]));
$magento_row["billing_company"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[15]));
$magento_row["billing_fax"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[24]));
$magento_row["shipping_prefix"] = "";
$magento_row["shipping_firstname"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[13]));
$magento_row["shipping_middlename"] = "";
$magento_row["shipping_lastname"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[14]));
$magento_row["shipping_suffix"] = "";
$magento_row["shipping_street_full"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[16]));
$magento_row["shipping_street1"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[16]));
$magento_row["shipping_street2"] = "";
$magento_row["shipping_street3"] = "";
$magento_row["shipping_street4"] = "";
$magento_row["shipping_street5"] = "";
$magento_row["shipping_street6"] = "";
$magento_row["shipping_street7"] = "";
$magento_row["shipping_street8"] = "";
$magento_row["shipping_city"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[17]));
$magento_row["shipping_region"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[19]));
$magento_row["shipping_country"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[20]));
$magento_row["shipping_postcode"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[21]));
$magento_row["shipping_telephone"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[23]));
$magento_row["shipping_company"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[15]));
$magento_row["shipping_fax"] = trim(preg_replace('/(\r\n|\r|\n)+/', ' ',$row[24]));
$magento_row["created_in"] = 'default';
$magento_row["is_subscribed"] = '0';
$magento_row["group"] = "General";
$magento_row["prefix"] = "";
$magento_row["middlename"] = "";
$magento_row["suffix"] = "";
$magento_row["taxvat"] = "";
//
$result[] = $magento_row;
$counter++;
}
$fp = fopen('magento_customers.csv', 'w');
foreach ($result as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment