【问题标题】:Migrate Old Site Users into Magento DB将旧站点用户迁移到 Magento DB
【发布时间】:2023-03-26 06:15:01
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: mysql magento magento-1.4 database-migration


    【解决方案1】:

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

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

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

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

    您可能需要将数据导出为 CSV 并以正确的格式将其导入 Magento。 30k 不算多,因此您甚至可以尝试默认 Magento 的正常导入过程。我们运气不好,但我们已经引进了数十万客户。即便如此,我们还是一次将文件分解为一小部分客户。

    【讨论】:

    • 是的,丹,我想我应该编写自定义脚本,因为记录不是 30,000,而是 300,000。实际上在新商店中,他们已经有超过 14,000 条记录。因此需要检查用户是否存在并根据他们的 API 数据库验证地址,然后才能存储。所以唯一的方法是编写自定义代码。谢谢,您还有其他教程或其他内容吗
    【解决方案2】:

    这是我如何使用 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 以使用相同的密码哈希架构。

    【讨论】:

    • 谢谢克里斯。我正在编写这个脚本。我会做出并发布回复。
    • 另外,我们从不检查电子邮件是否存在?是否可以通过 mage API 连接?
    • @Ela,我相信您应该能够首先检查客户是否存在。您只需要再次调用 API。 magentocommerce.com/wiki/doc/webservices-api/api/…在过滤器中使用电子邮件
    猜你喜欢
    • 2020-05-08
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-07-01
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多