You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopware 6 Store API按分类取商品列表时无法获取属性数据

Shopware 6 Store API 分类商品列表加载properties失败的解决办法

你的问题出在两个关键地方:

  1. 请求体结构不符合API规范
    Shopware 6的product-listing端点要求所有查询条件(分页、关联、字段过滤)必须包裹在criteria对象中,你直接传递参数的话,API无法正确解析关联规则,导致properties字段无法加载。

  2. Associations的写法错误
    你给group关联传了空数组[],这在Shopware API中表示仅加载关联实体的ID,而非完整数据,需要改成空对象{}才能按includes配置加载字段。

修正后的代码如下:

const params = {
  criteria: {
    limit: 100,
    includes: {
      product: ['id', 'name', 'properties', 'propertyIds'],
      property_group_option: ['id', 'name', 'group'],
      property_group: ['id', 'name'],
    },
    associations: {
      properties: {
        associations: {
          group: {},
        },
      },
    },
  },
};

const result = await $axios.post(
  `${$axios.defaults.baseURL}/product-listing/${input.categoryId}`,
  params
);

额外验证点:

  • 确认目标商品确实关联了属性组选项,若商品本身无属性,properties会返回null。
  • 检查请求使用的API Token是否拥有商品属性的读取权限。

内容的提问来源于stack exchange,提问作者Der Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 00:20:06