Search code examples
javascriptshopware

Extend plugin javascript file from another plugin


Is it possible in Shopware 6 to extend plugins with another plugin? I have plugin A from the shopware store, I need to change its functionality a bit, because it does not quite suit me. This plugin overrides core functionality of shopware - ListingPlugin from src / plugin / listing / listing.plugin. I need to get the js file from plugin A from my plugin B or from theme. I didn't find any information on this functionality from documentation


Solution

  • You can extend the plugin like

    import ExtendPlugin from './plugin/youtPluignFolder/extend-plugin.plugin';
    
    const PluginManager = window.PluginManager;
    PluginManager.override('OrgPlugin', ExtendPlugin);
    
    ...
    

    After register the file you need to create the file. There you can extend or overwrite the function like

    import OrgPlugin from '/app/custom/plugins/pluginName/path/to/plugin-file.plugin';
    
    export default class ExtendPlugin extends OrgPlugin {
        init() {
            super.init();
        }
    
        // Function you want overwrite or extend
        function () {
          //    your code
        }
    }