首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Shopware 6API/ Product /如何在响应中为每个产品添加可用的颜色变体

Shopware 6API/ Product /如何在响应中为每个产品添加可用的颜色变体
EN

Stack Overflow用户
提问于 2022-11-10 13:03:39
回答 1查看 38关注 0票数 1

API请求/存储-api/product/{categoryId}

我希望API响应中的每个产品都有可用的颜色变体。因为我想在产品列表页面上显示颜色变体。但是目前该数据不是由shopware 6 api提供的。

我试图通过使用关联来添加这些数据,但是没有帮助。

请求体

代码语言:javascript
运行
复制
{
    "includes": {
    "product": ["id", "productNumber", "cover", "options"]
  },
    "associations": {
        "options": {
            "media": []
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-10 14:38:08

请求体看起来是正确的。如果产品是变体,那么它应该有options的内容。

若要验证以下请求主体,请尝试:

代码语言:javascript
运行
复制
{
  "limit": 1,
  "includes": {
    "product": ["id", "productNumber", "options"],
    "property_group_option": ["name", "group"],
    "property_group": ["name"]
  },
  "associations": {
    "options": {
      "associations": {
        "group": []
      }
    }
  },
  "filters": [
    {
      "type": "not", 
      "operator": "and",
      "queries": [
        {
          "type": "equals",
          "field": "parentId",
          "value": null
        }
      ]
    }
  ]
}

这应该会产生一个单一的变量。

答复应与此类似:

代码语言:javascript
运行
复制
{
    "entity": "product",
    "total": 1,
    "aggregations": [],
    "page": 1,
    "limit": 1,
    "elements": [
        {
            "productNumber": "10042.1",
            "options": [
                {
                    "name": "linen",
                    "group": {
                        "name": "textile",
                        "apiAlias": "property_group"
                    },
                    "apiAlias": "property_group_option"
                },
                {
                    "name": "35",
                    "group": {
                        "name": "size",
                        "apiAlias": "property_group"
                    },
                    "apiAlias": "property_group_option"
                },
                {
                    "name": "chartreuse",
                    "group": {
                        "name": "shirt-color",
                        "apiAlias": "property_group"
                    },
                    "apiAlias": "property_group_option"
                }
            ],
            "id": "0002ea44c49c41ecb91c43e7e49e422d",
            "apiAlias": "product"
        }
    ],
    "states": [],
    "apiAlias": "dal_entity_search_result"
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74389460

复制
相关文章

相似问题

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