Magento 1.9.x - 如何更新订单中的客户ID

时间:2016-02-26 18:42:10

标签: magento magento-1.9 database-migration data-migration magento-1.4

我正在使用Magento CE 1.9.x,我目前的网站在Magento CE 1.4.x上运行

数据迁移后,每个订单中都缺少客户ID。

现在我想按顺序更新客户ID,我该怎么做?

任何想法?

2 个答案:

答案 0 :(得分:0)

以下是有关如何以编程方式更新每个订单的客户ID的示例

$orderCustomerMapping = array(
    1 => 123,
    2 => 124,
    // ...
    // order_id => customer_id
);

foreach ($orderCustomerMapping as $orderId => $customerId) {
    $order = Mage::getModel('sales/order')->load($orderId);
    $order->setCustomerId($customerId);
    $order->save();
}

答案 1 :(得分:0)

jraisanen的回答是正确的,但要完成关联,您还应该设置客户组ID并且是这样的访客标志:

$_order = Mage::getModel('sales/order')->load($order->getId());         
 $_order->setCustomerId($myCustomerId); //sets the customer id
 $_order->setCustomerIsGuest(0); //sets is guest to false
 $_order->setCustomerGroupId('1');//sets to the "general" customer group
 $_order->save();