Magento import X-Cart users
This script is allow to import the X-Cart users into Magento database.
<?php error_reporting(E_ALL ^ E_NOTICE); include "./auth.php"; include $xcart_dir.'/magento/app/Mage.php'; func_flush('Import users'); $users = func_query("select * from $sql_tbl[customers] where usertype='C' order by login limit 4400, 200"); if ($users) foreach($users as $index=>$user) { $customer = Mage::getModel('customer/customer')->setWebsiteId(1); $customer->loadByEmail($user['email']); if (!$customer->getId()) $customer = Mage::getModel('customer/customer')->setId(null); $user['password'] = text_decrypt($user['password']); if (strlen($user['password']) < 6) while(strlen($user['password']) < 6) $user['password'] .= substr(md5(time()), 1, 1); $data = array( 'firstname' => $user['firstname'], 'lastname' => $user['lastname'], 'email' => $user['email'], 'password' => $user['password'], 'confirmation' => $user['password'], 'website_id' => 1, ); $customer->addData($data); $customer->save(); if ($customer->getConfirmation() && $customer->isConfirmationRequired()) { $customer->setConfirmation(null); $customer->save(); } $data = array ( 'firstname' => $user['b_firstname'], 'lastname' => $user['b_lastname'], 'street' => explode("\n", $user['b_address']), 'city' => $user['b_city'], 'postcode' => $user['b_zipcode'], 'country_id' => $user['b_country'], 'telephone' => $user['phone'], ); $customAddress = Mage::getModel('customer/address'); $customAddress->setData($data) ->setCustomerId($customer->getId()) ->setIsDefaultBilling('1') ->setSaveInAddressBook('1'); $customAddress->save(); $data = array ( 'firstname' => $user['s_firstname'], 'lastname' => $user['s_lastname'], 'street' => explode("\n", $user['s_address']), 'city' => $user['s_city'], 'postcode' => $user['s_zipcode'], 'country_id' => $user['s_country'], 'telephone' => $user['phone'], ); $customAddress = Mage::getModel('customer/address'); $customAddress->setData($data) ->setCustomerId($customer->getId()) ->setIsDefaultShipping('1') ->setSaveInAddressBook('1'); $customAddress->save(); if ($index % 100 == 0) func_flush("<br>\n"); func_flush('.'); } func_flush("<br/>\nUsers - ok<br/>\n");
This scriipt should be placed to the root dir of the X-Cart, but before you are able to use this script, you should change the following line of the code:
include $xcart_dir.'/magento/app/Mage.php';
It's required to include the magento “Mage.php” here. For now it's presupposed that the Magento is installed to the “magento” subdir of the X-Cart.
Also you should note a few features of this script. There are no user login in default Magento installation, the mail is used instead. The import makes the same, so when the users will be imported, the user e-mail should be used as the user name instead of the login.
And more over, there is the security check in the Magento. The password length is checked (6 chars by default), so we have to extend the X-Cart password in some of the cases. The users with the extended password should use the password recovery tool to receive their new password.
PS: After the user import it is usually great idea to import the orders.