首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想填充商店软件v6管理api中的所有子对象

我想填充商店软件v6管理api中的所有子对象
EN

Stack Overflow用户
提问于 2022-05-16 14:57:43
回答 1查看 237关注 0票数 1

我想从order对象中填充子对象,比如传递、地址、paymentMethod等等--但是如何填充呢?针对{{shop_url}/api/search/order的POST查询体

代码语言:javascript
复制
    "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": []
            }
        }
    }
}

我得到以下答复:

代码语言:javascript
复制
     "deliveries": {
                    "data": [],
                    "links": {
                        "related": "https://xxx/api/order/<id>/deliveries"
                    }
                },

在我的第一次回复中,有没有办法从提供的链接中获取数据?多么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-18 07:41:48

您必须将要填充的对象添加到associationsincludes中,就像对lineItems所做的那样。例如,使用此请求获取送货、地址和付款方法:

代码语言:javascript
复制
{
    "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的响应中找到这些对象。

代码语言:javascript
复制
{
    "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": []
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72261278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档