Search code examples
shopware6

Shopware 6 product export error with customFields


Adding customFields in a product export (e.g. Shopzilla) in our shopware 6 migration throws the following exception. It is not possible to export customerFields not listed in the white list.

Failed rendering string template using Twig: Failed rendering string template using Twig: Key "custom_field_set_product_mybaby_pixi_swpixideliverydate" for array with keys "migration_mybaby_product_deal, migration_mybaby_product_attr1 ...

The message shows some white listed custom fields we created for migration. All other custom fields won't work anymore

This export column is not working:

{{ product.translated.customFields.custom_field_set_product_mybaby_pixi_swpixideliverydate }}

All other custom fields like "migration" are working

{{ product.translated.customFields.migration_mybaby_product_attr1 }}

Somehow the whitelist is not updateted with other custom fields except those for migration.

All custom fields should be exported with product export as the tutorial describes.


Solution

  • In this instance the twig renderer is using a strict policy and doesn't allow using undefined variables. Custom fields may not have been persisted yet and might therefore be undefined, depending on the product in this case. Check that the custom field is defined before using them.

    {% if product.translated.customFields.custom_field_set_product_mybaby_pixi_swpixideliverydate is defined %}
        {{ product.translated.customFields.custom_field_set_product_mybaby_pixi_swpixideliverydate }}
    {% endif %}