我想从 shopware v6 admin api 填充所有子对象

I want to populate all sub objects from a shopware v6 admin api

我想填充来自订单对象的子对象,例如送货、地址、付款方式等 - 但是如何呢? POST 针对 {{shop_url}}/api/search/order

的查询正文
    "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"
                    }
                },

有没有办法从我的第一个回复中提供的 link 中获取数据?怎么样?

您必须将要填充的对象添加到 associationsincludes,就像您对 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": []
}