我想从order对象中填充子对象,比如传递、地址、paymentMethod等等--但是如何填充呢?针对{{shop_url}/api/search/order的POST查询体
"ids": ["xxx"],
"includes": {
"order": ["id", "orderNumber", "createdAt", "lineItems", "orderCustomer", "currency", "language", "salesChannel", "addresses", "billingAddress", "meta", "shippingCosts", "deliveries" ],
"order_line_item": ["label", "position", "quantity", "unitPrice", "productId", "product", "price"],
"product": ["ean"]
},
"associations": {
"lineItems": {
"associations": {
"product": []
}
}
}
}我得到以下答复:
"deliveries": {
"data": [],
"links": {
"related": "https://xxx/api/order/<id>/deliveries"
}
},在我的第一次回复中,有没有办法从提供的链接中获取数据?多么?
发布于 2022-05-18 07:41:48
您必须将要填充的对象添加到associations和includes中,就像对lineItems所做的那样。例如,使用此请求获取送货、地址和付款方法:
{
"ids": ["xxx"],
"includes": {
"order": ["id", "orderNumber", "createdAt", "lineItems", "orderCustomer", "currency", "language", "salesChannel", "addresses", "billingAddress", "meta", "shippingCosts", "deliveries", "transactions" ],
"order_line_item": ["label", "position", "quantity", "unitPrice", "productId", "product", "price"],
"product": ["ean"]
},
"associations": {
"lineItems": {
"associations": {
"product": {}
}
},
"deliveries": {},
"addresses": {},
"transactions": {
"associations": {
"paymentMethod": {}
}
}
}
}然后您将在included的响应中找到这些对象。
{
"data": [
{
"id": "59eb05bcc72e4c8fb85634dfce27d9ff",
"type": "order",
"attributes": {
"orderNumber": "10052",
"shippingCosts": {
"unitPrice": 0.0,
"quantity": 1,
"totalPrice": 0.0,
"calculatedTaxes": [
{
"tax": 0.0,
"taxRate": 25.0,
"price": 0.0,
"extensions": []
}
],
"taxRules": [
{
"taxRate": 25.0,
"percentage": 100.0,
"extensions": []
}
],
"referencePrice": null,
"listPrice": null,
"extensions": []
},
"createdAt": "2022-05-16T15:22:25.405+00:00",
"apiAlias": null
},
...
}
],
"included": [
{
"id": "2ab1012505fe4e1ab8cc74ff617fd65a",
"type": "order_address",
"attributes": {
"versionId": "0fa91ce3e96a4bc2be4bd9ce752c3425",
"countryId": "5e9a60f273904621896f7ff6bff2a476",
"countryStateId": null,
"orderId": "59eb05bcc72e4c8fb85634dfce27d9ff",
"orderVersionId": "0fa91ce3e96a4bc2be4bd9ce752c3425",
"salutationId": "655d4bb9865d407692858b4edb540593",
"firstName": "xxx",
"lastName": "xxx",
"street": "xxx",
"zipcode": "xxx",
"city": "xxx",
"company": null,
"department": null,
"title": null,
"vatId": null,
"phoneNumber": "xxx",
"additionalAddressLine1": null,
"additionalAddressLine2": null,
"customFields": null,
"createdAt": "2022-05-16T15:22:25.396+00:00",
"updatedAt": null,
"apiAlias": null
},
...
},
{
"id": "6a294fe46d344bbd9c7cbbef33691544",
"type": "order_delivery",
"attributes": {
"versionId": "0fa91ce3e96a4bc2be4bd9ce752c3425",
"orderId": "59eb05bcc72e4c8fb85634dfce27d9ff",
"orderVersionId": "0fa91ce3e96a4bc2be4bd9ce752c3425",
"shippingOrderAddressId": "2ab1012505fe4e1ab8cc74ff617fd65a",
"shippingOrderAddressVersionId": "0fa91ce3e96a4bc2be4bd9ce752c3425",
"shippingMethodId": "d9befc806b1d40b5ac4eb6d7d93e1c85",
"stateId": "1481b0eaffeb43a7b35e4e7f92b8d26b",
"trackingCodes": [],
"shippingDateEarliest": "2022-05-17T00:00:00.000+00:00",
"shippingDateLatest": "2022-05-19T00:00:00.000+00:00",
"shippingCosts": {
"unitPrice": 0.0,
"quantity": 1,
"totalPrice": 0.0,
"calculatedTaxes": [
{
"tax": 0.0,
"taxRate": 25.0,
"price": 0.0,
"extensions": []
}
],
"taxRules": [
{
"taxRate": 25.0,
"percentage": 100.0,
"extensions": []
}
],
"referencePrice": null,
"listPrice": null,
"extensions": []
},
"createdAt": "2022-05-16T15:22:25.399+00:00",
"updatedAt": "2022-05-16T15:22:25.613+00:00",
"apiAlias": null
},
...
},
{
"id": "e45170b5221344dc8aa49bd723eaa281",
"type": "product",
"attributes": {
"ean": null,
"apiAlias": null
},
"links": {
"self": "http://localhost/api/product/e45170b5221344dc8aa49bd723eaa281"
},
"relationships": [],
"meta": null
},
{
"id": "eb8be118861546abbdfb1b9d28079ddc",
"type": "payment_method",
"attributes": {
"pluginId": null,
"name": "Credit card",
"distinguishableName": "Credit card",
"description": "",
"position": 2,
"active": true,
"afterOrderEnabled": false,
"customFields": null,
"availabilityRuleId": null,
"mediaId": null,
"formattedHandlerIdentifier": "handler_shopware_defaultpayment",
"createdAt": "2022-03-25T11:02:55.896+00:00",
"updatedAt": "2022-03-25T11:49:09.886+00:00",
"translated": {
"name": "Credit card",
"distinguishableName": "Credit card",
"description": "",
"customFields": []
},
"apiAlias": null
},
...
},
...
],
"links": {
"self": "http://localhost/api/search/order"
},
"meta": {
"totalCountMode": 0,
"total": 1
},
"aggregations": []
}https://stackoverflow.com/questions/72261278
复制相似问题