我想从Shopware V6 Admin API中填充所有子对象

发布于 2025-01-29 11:37:18 字数 903 浏览 4 评论 0原文

我想从订单对象(例如交货,地址,付款方式等)中填充子对象 - 但是如何呢? 查询发布{{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"
                    }
                },

有没有办法在我的第一个响应中从提供的链接中获取数据?如何?

I want to populate sub objects from order object like deliveries, addresses, paymentMethod, etc. - but how?
Query Body of POST against {{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": []
            }
        }
    }
}

I get following response:

     "deliveries": {
                    "data": [],
                    "links": {
                        "related": "https://xxx/api/order/<id>/deliveries"
                    }
                },

Is there a way to get data from provided link in my first response? How?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2025-02-05 11:37:18

您必须将要填充的对象添加到sepociationsincold 就像使用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": {}
            }
        }
    }
}

然后,您将在中的响应中找到这些对象,包括

{
    "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": []
}

You have to add the objects you want to populate to the associations and includes just like you did with the lineItems. Use for example this request to get deliveries, addresses and payment method:

{
    "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": {}
            }
        }
    }
}

Then you will find those objects in the response in 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": []
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文