2017-06-08 12 views
0

注文した後で注文を編集する方法を理解しようとしています。 注文をエクスポートするかどうかにかかわらず、カスタム属性を作成しました。Magento 2 Rest API注文の編集

ステータスがエクスポートされていないオーダーをすべて取得し、エクスポートした後、カスタム属性をエクスポートするように変更したいとします。

注文を編集/更新するためのRESTリクエストとは何ですか?私も試してみました

$json = array(
     "entity_id" => $id, 
     "extension_attributes" => array(
      "custom_export_attribute" => "exported", 
      ) 
     ); 
    $webapi = new ApiClient('https://dev.local.nl', self::$username, self::$password); 
    $response = $webapi->getClient()->request('PUT', '/rest/V1/orders/create', [ 

     'headers' => [     
      'Authorization'    => "Bearer " . $webapi->getToken(), 
      'Content-Type'    => "application/json" 
     ], 
     'body'  => json_encode($json) 

    ]);  
    return json_decode($response->getBody(), true); 

:これは私のコードです

{"message":"%fieldName is a required field.","parameters": 
{"fieldName":"entity"} 

$webapi->getClient()->request('PUT', '/rest/V1/orders/'.$id, 

答えて

0

注文の詳細を更新/編集するには、Magentoの2 /V1/ordersPOSTを受け入れ、私は次のようなエラーメッセージを取得しておきますリクエストメソッド。 Magento 2 Dev Docあたりとして、それは(あなたはドキュメントのページ全体JSON要求を見つけることができます)形式以下でリクエストボディを受け入れる:

$json = [ 
    "entity"=> [ 
     "entity_id" => $id, 
     "extension_attributes" => [ 
      "custom_export_attribute" => "exported" 
     ] 
    ] 
] 

:だから

{ 
    "entity": { 
     "entity_id": 0, 
     "extension_attributes": { 

     } 
    } 
} 

、あなただけのよう$json変数を更新する必要がありますそしてPUTの代わりにPOSTリクエストメソッドを呼び出すよりも。私の提案では、新しい注文作成のためにCreate APIを使用することを好む。

関連する問題