Reputation: 1078
I'm trying to fetch the parent of a specific product using the store-api.
When I'm adding the parent
association, I get the error code FRAMEWORK__PARENT_ASSOCIATION_CAN_NOT_BE_FETCHED
Do I really have to do a second request using the parentId
to get some of the parent product information or is there another way?
Upvotes: 3
Views: 2299
Reputation: 349
Instead of trying to find the parent of one variant, you could try searching for products where a child has the ID "xyz". Shopware supports filtering for nested objects like "children.id".
For example:
POST /store-api/product
Content-Type: application/json
Accept: application/json
sw-access-key: ...
sw-language-id: ...
{
"includes": {
"product": ["productNumber", "children", "name", "translated.name"]
},
"associations": {
"children": []
},
"filter": [
{"field": "children.id", "type": "equals", "value": "f87a875bc5fa47e08ea40a19ce9c5627"}
]
}
Should give you parent and children output:
{
"entity": "product",
"total": 1,
"aggregations": [],
"page": 1,
"limit": null,
"elements": [
{
"productNumber": "252009 00-0002",
"name": null,
"children": [
{
"productNumber": "252009 00-0002.3",
"name": null,
"children": null,
"translated": {
"name": "T-Shirt Logo"
},
"apiAlias": "product"
},
{
"productNumber": "252009 00-0002.1",
"name": null,
"children": null,
"translated": {
"name": "T-Shirt Logo"
},
"apiAlias": "product"
},
{
"productNumber": "252009 00-0002.4",
"name": null,
"children": null,
"translated": {
"name": "T-Shirt Logo"
},
"apiAlias": "product"
},
{
"productNumber": "252009 00-0002.2",
"name": null,
"children": null,
"translated": {
"name": "T-Shirt Logo"
},
"apiAlias": "product"
}
],
"translated": {
"name": "T-Shirt Logo"
},
"apiAlias": "product"
}
],
"apiAlias": "dal_entity_search_result"
}
Upvotes: 6
Reputation: 905
I think you have to only use additional API-call with a parentId. As it is restricted deep inside EntityReader. Also, it is possible to implement your own ApiRoute and fetch all information by one API call.
Also please check the response for your child product. As almost all fields of the product are inherited, may you already get the information that you need in the first response.
Upvotes: 2