【问题标题】:Magento 2 Rest API Order editMagento 2 Rest API 订单编辑
【发布时间】:2017-12-31 13:23:00
【问题描述】:

我正试图弄清楚如何在我请求后编辑订单。 无论是否导出订单,我都做了一个自定义属性。

我首先得到所有状态为未导出的订单,导出它们后,我想将自定义属性更改为导出。

编辑/更新订单的 REST 请求是什么?我不断收到错误消息,例如:

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

这是我的代码:

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

我也试过了:

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

【问题讨论】:

    标签: rest magento2 guzzle


    【解决方案1】:

    要编辑/更新订单详细信息,Magento 2 /V1/orders 接受 POST 请求方法。根据Magento 2 Dev Doc,它接受以下格式的请求正文(您可以在文档页面中找到整个 JSON 请求):

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

    因此,您只需将$json 变量更新为:

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

    然后使用POST 请求方法而不是PUT 调用。在我的建议中,更喜欢使用Create API 来创建新订单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多