2016-07-07 102 views
0

我正在通過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

回答

0

到可能會面臨同樣的問題的人,我發現它是無法通過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); 
} 
-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));