将旧站点用户迁移到Magento DB

时间:2011-01-19 21:24:33

标签: mysql magento magento-1.4 database-migration

我在旧的在线商店拥有超过300,000名用户。客户端切换到Magento解决方案,现在必须将所有用户,地址迁移到Magento。所以我必须编写一个自定义脚本来将用户及其地址导入Magento系统。

是否已经完成了任何教程或类似的工作。请帮我。

由于

2 个答案:

答案 0 :(得分:3)

以下是我如何使用SOAP库将用户从OSC迁移到Magento的示例。这个脚本在旧服务器上运行,需要从ssh命令行运行(php执行时通过浏览器不支持这个

    $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);

您需要注意的一件事是密码..为此,我必须设置Magento使用相同的密码散列模式。

答案 1 :(得分:1)

我的建议是查看客户导入api并使用代码库中的方法构建脚本,使用API​​将会变慢,因为您将在服务器上运行脚本,您可以使用实际方法。因此,您可以查看此文件夹中的客户api类和方法

/应用程序/代码/核心/法师/客户/型号/客户

然后这里是地址api类和方法

/应用程序/代码/核心/法师/客户/型号/地址/

您可能需要将数据导出为CSV并以正确的格式将其导入Magento。 30k并不是那么多,所以你甚至可以尝试默认Magento的正常导入过程。我们没有好运,但我们已经进口了数十万客户。即便如此,我们一次将文件分成小块客户。