Search code examples
shopwareshopware6

Shopware 6 Plugin Custom config


I am developing a plugin in shopware 6 and for the configuration view of the plugin I am using the config.xml

I need to add some dynamic behavior that depends on configuration values so I wanted to know if i can make my own config without having to use the config.xml


Solution

  • The config.xml is a convenience feature. As such for its ease of use it comes with some limitations. However nothing is keeping you from adding custom entities and managing them to your liking with your own custom administration modules.

    As a sort of middle ground you can also add custom config fields in the config.xml. This will allow you to use a specific component, which could also be a custom component introduced by you, for handling inputs and storing of the data.

    <component name="my-custom-component">
       <name>My Custom Component</name>
    </component>
    
    Shopware.Component.register('my-custom-component', {
        template,
    
        props: {
            value: {
                type: String,
                required: false,
                default: '',
            },
        },
    
        data() {
            return {
                currentValue: this.value,
            };
        },
    
        watch: {
            value(value) {
                this.currentValue = value;
            },
        },
    
        methods: {
            onChange(event) {
                this.$emit('change', this.currentValue);
            },
        },
    });
    
    <sw-text-field
        :value="currentValue"
        @change="onChange"
    />