Magento从REST API更改订单状态

问题描述:

我正在通过C#ASP.NET MVC应用程序中的REST API与Magento网络应用程序(版本1.9.2.2)“沟通”。Magento从REST API更改订单状态

该应用程序本质上充当比萨饼的后端订单流量仪表板。我需要显示最新的订单,并允许用户在处理物品时(除其他之外)检查物品。

我能够检索订单,产品,客户等;但需要能够更新订单状态。从我的研究看来,这可以通过添加订单评论来实现。

这就是说,我的问题如下:

  1. 是增加订单注释在Magento 1.9(从而更新订单状态),通过SOAP服务只可能吗?
  2. 如果以上情况属实,如何使用另一安全方法更新特定订单的订单状态?

对REST API文档:http://devdocs.magento.com/guides/m1x/api/rest/Resources/Orders/order_comments.html

到可能会面临同样的问题的人,我发现它是无法通过REST API更新订单状态(AKA新增销售订单注释) 。您必须使用SOAP API,而版本2使其变得最简单。

设置:

  1. 在Magento,创建SOAP角色和用户
  2. 作为一个Web引用添加SOAP V2 API到Visual Studio项目

代码:

public void UpdateOrderStatus(string orderIncrementId, string newStatus, string comment = "") 
{ 
    // Init service with uri 
    var service = new MagentoSoap.MagentoService(); 
    // Login - username and password (soap api key) of the soap user 
    string sessionId = service.login(Username, Password); 
    // Update order status 
    service.salesOrderAddComment(sessionId, orderIncrementId, newStatus, comment, 1, true); 
} 

您可以使用addComment方法执行此操作,该方法还允许您将新订单状态指定为其参数之一。

$sku='100000003'; 
$orderStatus = 'Downloaded'; 
$comment = 'The order was successfully downloaded'; 
$sendEmailToCustomer = false; 

$proxy->call($sessionId, 'sales_order.addComment', array($sku, $orderStatus, $comment, $sendEmailToCustomer));