Magento从REST API更改订单状态

时间:2016-07-07 15:00:46

标签: c# api rest magento magento-1.9

我正在沟通'使用Magento Web应用程序(版本1.9.2.2)通过C#ASP.NET MVC应用程序中的REST API。

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

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

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

  1. 是否只能通过Magento 1.9中的SOAP服务添加订单注释(从而更新订单状态)?
  2. 如果以上情况属实,我如何使用其他安全方法更新特定订单的订单状态?
  3. REST API文档:http://devdocs.magento.com/guides/m1x/api/rest/Resources/Orders/order_comments.html

2 个答案:

答案 0 :(得分:1)

对于可能面临同一问题的任何人,我发现无法通过REST API更新订单状态(AKA添加销售订单评论)。您必须使用SOAP API,而版本2使它变得最简单。

<强>设定:

  1. 在magento中,创建SOAP角色和用户
  2. 将SOAP v2 API添加为Visual Studio项目的Web引用
  3. <强>代码:

    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);
    }
    

答案 1 :(得分:-1)

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

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

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