phpshopware

Add custom entity type for custom field in Shopware 6


In Shopware 6.4.0.0 it is possible to add custom fields which are based on Entities.

The list of entity types is limited:

New custom field dialog

Is it easily possible to add additional entity types, such as a list of available product properties?

EDIT https://github.com/shopware/platform/blob/trunk/src/Administration/Resources/app/administration/src/module/sw-settings-custom-field/component/sw-custom-field-type-entity/index.js#L9


Solution

  • It is enough to add something like

                {
                    label: "Product Property Group",
                    value: 'property_group'
                }
    

    to the select

    https://github.com/shopware/platform/blob/trunk/src/Administration/Resources/app/administration/src/module/sw-settings-custom-field/component/sw-custom-field-type-entity/index.js#L9

    Then it is possible to create a custom field that lets us chose product properties.

    Next we have to make this change persistent.

    See https://developer.shopware.com/docs/guides/plugins/plugins/administration/customizing-components

    Shopware.Component.override('sw-custom-field-type-entity', {
        computed: {
        entityTypes() {
            const types = this.$super('entityTypes');
    
            types.push(
                {
                    label: 'Product Property Group',
                    value: 'property_group'
                }
            );
    
            return types;
        }
        }
    });