magento -- 关于更新订单状态的API接口函数

做Magento和其他系统的对接时需要调用Magento的Api,原以为更新一个订单的状态这样的函数Magento默认肯定自带有,一开始却找不到,打开官网看order部分提供的接口函数列表也没找到。


magento -- 关于更新订单状态的API接口函数

 

说明,从上到下依次为批量获取订单,获取单个订单,给订单添加备注,锁定订单,解锁订单和取消订单。在我认为不存在这个函数准备自己写一个的时候,看代码发现其实addComment这个函数已经提供了更新订单状态的功能,而不仅仅是添加备注,看代码

public function addComment($orderIncrementId, $status, $comment = null, $notify = false) { $order = $this->_initOrder($orderIncrementId); $order->addStatusToHistory($status, $comment, $notify); try { if ($notify && $comment) { $oldStore = Mage::getDesign()->getStore(); $oldArea = Mage::getDesign()->getArea(); Mage::getDesign()->setStore($order->getStoreId()); Mage::getDesign()->setArea('frontend'); } $order->save(); $order->sendOrderUpdateEmail($notify, $comment); if ($notify && $comment) { Mage::getDesign()->setStore($oldStore); Mage::getDesign()->setArea($oldArea); } } catch (Mage_Core_Exception $e) { $this->_fault('status_not_changed', $e->getMessage()); } return true; }

addStatusToHistory这个函数可以同时修改订单状态和添加订单备注,并且添加一条订单历史记录,要比直接修改订单的状态值要合理。同时addComment这个接口还可以发送订单更新邮件给客户,是否发送取决于$notify这个参数。

也就是说,Magento提供的更新订单的接口还是挺完整的,可惜文档里没体现出来,会误导人。