我想将客人订单链接到 Magento 中的现有帐户。有人知道我必须更改哪些表上的哪些字段才能完成此操作吗?
有没有更简单的方法?
这似乎也有效..
$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();
}
如果您使用的是 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
由于从后端从 order 中获取 increment_id 比从 entity 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
要扩展 RS 发布的内容:
如果您希望管理订单屏幕反映成员所在的组,则需要多几行:
$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();
我正在使用 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 更改为新的 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