本文介绍如何在Magento中以编程方式更改您的订单状态。
首先,您需要加载订单。
您可以通过
order_id或
order_increment_id加载订单
。
通过“订单ID”加载订单
$orderId = YOUR_ORDER_ID;
$order = Mage::getModel('sales/order')->load($orderId);
通过“订单增量编号”加载订单
$orderIncrementId = YOUR_ORDER_INCREMENT_ID;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
将订单状态更改为“完成”
/**
* change order status to 'Completed'
*/
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();
将订单状态更改为待处理,处理中,已取消,已关闭,已暂停等
/**
* change order status to 'Pending'
*/
$order->setState(Mage_Sales_Model_Order::STATE_NEW, true)->save();
/**
* change order status to 'Pending Paypal'
*/
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
/**
* change order status to 'Processing'
*/
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
/**
* change order status to 'Completed'
*/
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true)->save();
/**
* change order status to 'Closed'
*/
$order->setState(Mage_Sales_Model_Order::STATE_CLOSED, true)->save();
/**
* change order status to 'Canceled'
*/
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
/**
* change order status to 'Holded'
*/
$order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true)->save();
取消订单
if($order->canCancel()) {
$order->cancel()->save();
}
等待订单
if($order->canHold()) {
$order->hold()->save();
}
取消订单
if($order->canUnhold()) {
$order->unhold()->save();
}