【问题标题】:Magento Change Order Status from REST API来自 REST API 的 Magento 更改订单状态
【发布时间】:2016-07-07 15:00:45
【问题描述】:

我正在通过 C# ASP.NET MVC 应用程序中的 REST API 与 Magento Web 应用程序(版本 1.9.2.2)“通信”。

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

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

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

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

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

【问题讨论】:

    标签: c# api rest magento magento-1.9


    【解决方案1】:

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

    设置:

    1. 在 magento 中,创建一个 SOAP 角色和用户
    2. 将 SOAP v2 API 作为 Web 引用添加到您的 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);
    }
    

    【讨论】:

      【解决方案2】:

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

      $sku='100000003';
      $orderStatus = 'Downloaded';
      $comment = 'The order was successfully downloaded';
      $sendEmailToCustomer = false;
      
      $proxy->call($sessionId, 'sales_order.addComment', array($sku, $orderStatus, $comment, $sendEmailToCustomer));
      

      【讨论】: