将客户订单链接到magento中的现有客户帐户

时间:2012-07-10 08:41:39

标签: magento

我想将来宾订单链接到Magento中的现有帐户。 有人知道我必须更改哪些表来完成此操作吗?

有没有更简单的方法?

5 个答案:

答案 0 :(得分:8)

这似乎也有效..

$order_id = 5;  // Your Order ID
$customer_id = 7;  //Customer ID

$_order = Mage::getModel('sales/order')->load($order_id);

if($_order->getCustomerId() == NULL){
    $_order->setCustomerId($customer_id);
    $_order->save();
}

答案 1 :(得分:6)

如果您使用的是Magento> = 1.4.1,则可以在数据库中运行该程序:

UPDATE sales_flat_order 
   SET customer_id = YOUR_CUSTOMER_ID_HERE 
WHERE entity_id = YOUR_ORDER_ID_HERE AND customer_id IS NULL

您还需要升级“网格”表:

UPDATE sales_flat_order_grid 
    SET customer_id = YOUR_CUSTOMER_ID_HERE 
WHERE entity_id = YOUR_ORDER_ID_HERE AND customer_id IS NULL

答案 2 :(得分:3)

从后端开始,从命令获取increment_id比实体id更容易,我更喜欢使用以下两个查询:

UPDATE sales_flat_order 
  SET customer_id = YOUR_CUSTOMER_ID_HERE, customer_is_guest=0, customer_group_id = YOUR_CUSTOMER_GROUP_ID_HERE
  WHERE increment_id = YOUR_INCREMENT_ID_HERE AND customer_id IS NULL

UPDATE sales_flat_order_grid 
  SET customer_id = YOUR_CUSTOMER_ID_HERE, 
  WHERE increment_id = YOUR_INCREMENT_ID_HERE AND customer_id IS NULL

答案 3 :(得分:1)

扩展R.S发布的内容:

如果您希望管理订单屏幕反映该成员所在的组,则需要更多行:

$customer_id = xxxx;  //Customer ID
$order_increment_id = xxxxxxxxx; //Admin order increment id
$_order = Mage::getModel('sales/order')->loadByIncrementId($order_increment_id);

if($_order->getCustomerId() == NULL){
    $_order->setCustomerId($customer_id);
}

if($_order->getCustomerIsGuest() == "1"){
    $_order->setCustomerIsGuest(0);
}

if($_order->getCustomerGroupId() == "0"){
    $_order->setCustomerGroupId(1);
}

$_order->save();

答案 4 :(得分:0)

我使用的是magento 1.9.0.1,我用来更改以下信息:
对于表 sales_flat_order
=>将 customer_id 从NULL更改为 new customer_id
=> customer_is_guest 0

同样适用于表 sales_flat_order_grid
=>将 customer_id 从NULL更改为 new customer_id

以下2个查询将完成此任务:

UPDATE sales_flat_order 
  SET customer_id = (Your_Customer_ID), customer_is_guest=0 
  WHERE entity_id = Your_Order_ID_HERE AND customer_id IS NULL

UPDATE sales_flat_order_grid 
  SET customer_id = Your_Customer_ID 
  WHERE entity_id = Your_Order_ID AND customer_id IS NULL