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

Shopware 6迁移中产品导出自定义字段白名单异常问题

解决Shopware 6迁移后自定义字段无法导出至Shopzilla等渠道的问题

问题根源

Shopware 6的第三方产品导出(比如Shopzilla)默认有自定义字段白名单机制,仅放行以migration_开头的迁移类自定义字段。非此类字段会触发Twig渲染失败,报错示例:

"custom_field_set_product_mybaby_pixi_swpixideliverydate"不在白名单的键列表中

解决方案

1. 通过事件订阅者扩展白名单

创建一个事件订阅者,监听产品导出收集事件,把所有自定义字段加入白名单:

<?php

namespace YourPlugin\Subscriber;

use Shopware\Core\Content\Product\Events\ProductExportCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class ProductExportCustomFieldsSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            ProductExportCollectorEvent::class => 'onProductExportCollect',
        ];
    }

    public function onProductExportCollect(ProductExportCollectorEvent $event): void
    {
        $criteria = $event->getCriteria();
        $customFieldSets = $event->getContext()->getExtension('custom_field_sets');
        
        if (!$customFieldSets) {
            return;
        }

        foreach ($customFieldSets as $set) {
            foreach ($set->getFields() as $field) {
                $associationName = 'custom_field_' . $field->getName();
                $criteria->addAssociation($associationName);
            }
        }
    }
}

接着在插件的services.xml里注册这个订阅者:

<service id="YourPlugin\Subscriber\ProductExportCustomFieldsSubscriber">
    <tag name="kernel.event_subscriber"/>
</service>

2. 调整导出模板(按需)

如果导出模板里需要直接调用自定义字段,确保字段名正确即可,比如在Shopzilla模板里:

<delivery_date>{{ product.custom_field_set_product_mybaby_pixi_swpixideliverydate }}</delivery_date>

3. 验证

  • 清空Shopware缓存
  • 重新执行产品导出,检查非迁移类自定义字段是否正常导出,无报错

内容的提问来源于stack exchange,提问作者Marian Steinhorst

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 07:22:11