Search code examples
vue.jsshopwareshopware6

Retrieve config value from sales channel in plugin settings


How can I retrieve values from the plugin config for a specific sales channel? I need to validate an API-Token, but can only retrieve the value stored for all sales channels and don't know how my custom admin component could even know about its current sales channel.

Currently, I am retrieving values via the following code, which follows the example plugin from Shopware, but they too only retrieve the global value.

Component.register('my-component', {
    computed: {
        getMyKey() {
            return this.pluginConfig['MyPlugin.config.myKey'];
        },
        pluginConfig() {
            let $parent = this.$parent;
            while ($parent.actualConfigData === undefined) {
                $parent = $parent.$parent;
            }
            return $parent.actualConfigData.null;
        }
    }
}

Solution

  • I was finally able to retrieve values for the currently selected sales channel:

    const getParentWithConfig = () => {
        let $parent = this.$parent;
    
        while ($parent.actualConfigData === undefined) {
            $parent = $parent.$parent;
        }
      
        return $parent;
    }
    
    const salesChannelId = this.getParentWithConfig().currentSalesChannelId;
    const values = this.systemConfigApiService.getValues('MyPlugin.config', salesChannelId);