9

I have tried calling [POST] /carts/mine/items, headers with correct bearer, and body:

{
    "cart_item": 1,
    "sku": "MY_SKU",
    "qty": 1
}

and I get the folowing response:

{
   "message": "Invalid value of \"%value\" provided for the %fieldName field.",
   "parameters": {
      "fieldName": "qty",
      "value": null
   }
}

Two things, I do not understand what to put in cart_item (but it is required) and I do not why it keeps telling me qty is null?

4

2 回答 2

11

首先应该使用带有空主体的请求创建空购物车:

[POST] {base URL}/rest/V1/carts/mine

作为回应,您将获得您的购物车/报价的 ID。

现在您可以使用以下方式将商品添加到购物车:

[POST] {base URL}/rest/V1/carts/mine/items
{
  "cart_item": {
    "quote_id": <cart ID received from previous call>,
    "sku": "product_sku",
    "qty": 10
  }
}

作为回应,您应该获取您的购物车商品数据:

{
  "item_id": 1,
  "sku": "product_sku",
  "qty": 10,
  "name": "Simple Product",
  "price": 123,
  "product_type": "simple",
  "quote_id": "1"
}

请小心,因为如果多次执行相同的请求,您可能会不小心使用 POST 请求更新现有的购物车商品数量。

于 2015-11-16T22:13:59.973 回答
0

这是对@Alex Palirush 答案的补充,感谢您清楚地解释它。

报价 ID 必须是整数,否则它将通过错误未知字段 cartId。

{
  "message": "No such entity with %fieldName = %fieldValue",
  "parameters": {
    "fieldName": "cartId",
    "fieldValue": "0"
  }
}
于 2017-09-28T13:41:15.983 回答