【问题标题】:Shopware 6 API / Product Listing / How to add available color variants for each product on the responseShopware 6 API / 产品清单 / 如何在响应中为每个产品添加可用的颜色变体
【发布时间】:2022-11-10 22:38:08
【问题描述】:

API 请求 /store-api/product-listing/{categoryId}

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

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

请求正文

{
    "includes": {
    "product": ["id", "productNumber", "cover", "options"]
  },
    "associations": {
        "options": {
            "media": []
        }
    }
}

【问题讨论】:

    标签: shopware6 shopware6-api


    【解决方案1】:

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

    要验证尝试以下请求正文:

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

    这应该会产生一个变体。

    响应应与此类似:

    {
        "entity": "product",
        "total": 1,
        "aggregations": [],
        "page": 1,
        "limit": 1,
        "elements": [
            {
                "productNumber": "0002ea44c49c41ecb91c43e7e49e422d",
                "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"
    }
    

    【讨论】:

      猜你喜欢
      • 2023-01-20
      • 2022-08-16
      • 1970-01-01
      • 2023-01-03
      • 2021-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多