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

Shopware 6 App实体扩展添加及商品分类customFields查询咨询

Shopware App商品列表获取分类customFields解决方案
  • 用Shopware的product_list扩展点,在App的manifest.xml里注册扩展,直接请求关联的分类数据及customFields:

    <extension target="product_list" xmlns="http://schema.shopware.com/app">
        <label>加载商品分类及自定义字段</label>
        <script>
            {
                "entity": "product",
                "associations": {
                    "categories": {
                        "associations": {
                            "customFields": {}
                        }
                    }
                }
            }
        </script>
    </extension>
    

    这样商品列表加载时,每个商品都会自动带上关联分类及对应的customFields数据。

  • 重写box-standard.html.twig后,直接通过商品对象的关联属性访问:

    {% for category in product.categories %}
        {% if category.customFields %}
            {# 替换成你的自定义字段名,比如customFields.category_tag #}
            <span>{{ category.customFields.category_tag }}</span>
        {% endif %}
    {% endfor %}
    
  • 如果扩展点方式不适用,就在navigation-page-loaded事件里批量请求API:
    获取商品ID列表后,调用/api/product接口,带上关联参数拉取分类及自定义字段:

    const productIds = products.map(p => p.id);
    Shopware.Service('apiClient').get('/api/product', {
        params: {
            ids: productIds.join(','),
            associations: {
                categories: {
                    associations: {
                        customFields: {}
                    }
                }
            }
        }
    }).then(res => {
        // 这里处理返回的商品数据,已经包含分类customFields
    });
    

内容的提问来源于stack exchange,提问作者Leon Schwanitz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 21:35:18