4

I have more than 300,000 users on an old online store. Client switched to Magento solution and now have to migrate all the users, addresses to Magento. So I have to write a custom script to import users and their address to the Magento system.

Are there any tutorials or similar sort of work already done. Please help me.

Thanks

Elamurugan
  • 3,204
  • 13
  • 59
  • 104

2 Answers2

3

Here's an example of how I migrated users from OSC into Magento with the SOAP library. This script was run on the old server and needs to be run from the ssh command line (php execution time through the browser will not support this

    $proxy = new SoapClient('http://[your magento url]/api/soap/?wsdl=1');
    $sessionId = $proxy->login('admin', '[your password]');

    // connect to local db

    $link = mysql_connect('localhost', '[old ecommerce db]', '[old db pw]');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db('sbc_osc', $link);

    $sql = "SELECT * FROM customers";

    $customers = mysql_query($sql);

    // loop thyrough customers
    while ($customer = mysql_fetch_assoc($customers)) {

        set_time_limit(600);

        $newCustomer = array(
            'firstname'  => $customer['customers_firstname'],
            'lastname'   => $customer['customers_lastname'],
            'email'      => $customer['customers_email_address'],
            'password_hash' => $customer['customers_password'],
            'store_id'   => 2, // set the store you want to send to
            'website_id' => 2
        );

        $telephone = $customer['customers_telephone'];
        $fax = $customer['customers_fax'];

        try{
            $newCustomerId = $proxy->call($sessionId, 'customer.create', array($newCustomer));
        }
        catch (Exception $e) {
            echo "failed to create customer for: " . $customer['customers_firstname'] . " " . $customer['customers_lastname'] . "\n";
        }

        // grab the default address
        $sql = "SELECT ab.*, c.countries_iso_code_2, z.zone_name, z.zone_id
                FROM address_book ab 
                LEFT JOIN countries c ON ab.entry_country_id =  c.countries_id
                LEFT JOIN zones z ON ab.entry_zone_id = z.zone_id
                WHERE customers_id = {$customer['customers_id']} AND address_book_id = {$customer['customers_default_address_id']}";

        $addresses = mysql_query($sql);

        while ($address = mysql_fetch_assoc($addresses)) {

            $newCustomerAddress = array(
                'firstname'  => $address['entry_firstname'],
                'lastname'   => $address['entry_lastname'],
                'company'    => $address['entry_company'],
                'country_id' => $address['countries_iso_code_2'],
                'region_id'  => $address['zone_id'],
                'region'     => ($address['zone_name'] != "" ? $address['zone_name'] : $address['entry_state']),
                'city'       => $address['entry_city'],
                'street'     => array($address['entry_street_address']),
                'telephone'  => $telephone,
                'fax'        => $fax,
                'postcode'   => $address['entry_postcode'],
                'is_default_billing'  => true,
                'is_default_shipping' => true,
            );

            try{
                $newAddressId = $proxy->call($sessionId, 'customer_address.create', array($newCustomerId, $newCustomerAddress));
            }
            catch (Exception $e) {
                echo "failed to add address for: " . $address['entry_firstname'] . " " . $address['entry_lastname'] . "\n";
            }
        }

        echo "migrated: " . $customer['customers_firstname'] . " " . $customer['customers_lastname'] . "\n";

    }


    mysql_close($link);

One thing you need to watch out for is the passwords.. for this to work I had to set up Magento to use the same password hashing schema.

Drew Hunter
  • 10,136
  • 2
  • 40
  • 49
Chris
  • 1,731
  • 3
  • 24
  • 38
  • Thanks Chris. I am working on this script. I will make and post the reply. – Elamurugan Jan 20 '11 at 19:11
  • Also here we never check for already email existence or not? Is it possible via mage API connect? – Elamurugan Jan 20 '11 at 19:47
  • @Ela, I believe you should be able to check for the customers existence first. You'll just need to make another call to the API. http://www.magentocommerce.com/wiki/doc/webservices-api/api/customer#customer.list Use email ini the filter – Chris Jan 20 '11 at 22:30
1

My suggestion would be to look into the customer import api and build out a script using the methods from the code base, using the API will be slower so since you will be running the script on your server you can build it using the actual methods. So you can look at this folder for the customer api classes and methods

/app/code/core/Mage/Customer/Model/Customer

and then here for the address api classes and methods

/app/code/core/Mage/Customer/Model/Address/

You would probably need to export your data to CSV and get it in the right format to import into Magento. 30k isn't that much so you can even try out the normal import process that is default Magento. We haven't had good luck with that but we have been importing hundreds of thousands of customers. Even then we break the file down into small chunks of customers at a time.

dan.codes
  • 3,523
  • 9
  • 45
  • 59
  • Yes dan, i think i should write custom script, since the records are not 30,000, its 300,000. and actually in the new store they already have more than 14,000 records.so need to to check for user existence and validating address against their API db then only can store. So only way is to write custom code. Thanks, and do you have any more tutorial or something for this – Elamurugan Jan 20 '11 at 20:00