Add plugin dependencies
New in Shopware 6 is the possibility to properly require on other plugins to be in the system. This is done using the require feature from composer. Further information about this can be found in the official composer documentation.

Setup

Each plugin for Shopware 6 has to own a composer.json file for it to be a valid plugin. Creating a plugin is not explained here, make sure to read our Plugin base guide first.
Since every plugin has to own a composer.json file, you can simply refer to this plugin by its technical name and its version mentioned in the respective plugin's composer.json.
So, those are example lines of the SwagBasicExample plugin's composer.json:
1
{
2
"name": "swag/swag-basic-example",
3
"description": "Plugin quick start plugin",
4
"version": "v1.0.0",
5
...
6
}
Copied!
Important to note is the name as well as the version mentioned here, the rest of the file is not important for this case here. You're going to need those two information to require them in your own plugin.
In order to require the SwagBasicExample plugin now, you simply have to add these two information to your own composer.json as a key value pair:
<plugin root>/composer.json
1
{
2
"name": "swag/plugin-dependency",
3
"description": "Plugin requiring other plugins",
4
"version": "v1.0.0",
5
"type": "shopware-platform-plugin",
6
"license": "MIT",
7
"authors": [
8
{
9
"name": "shopware AG",
10
"role": "Manufacturer"
11
}
12
],
13
"require": {
14
"shopware/core": "6.1.*",
15
"swag/SwagBasicExample": "v1.0.0"
16
},
17
"extra": {
18
"shopware-plugin-class": "Swag\\PluginDependency\\PluginDependency",
19
"label": {
20
"de-DE": "Plugin mit Plugin-Abhängigkeiten",
21
"en-GB": "Plugin with plugin dependencies"
22
},
23
"description": {
24
"de-DE": "Plugin mit Plugin-Abhängigkeiten",
25
"en-GB": "Plugin with plugin dependencies"
26
}
27
},
28
"autoload": {
29
"psr-4": {
30
"Swag\\PluginDependency\\": "src/"
31
}
32
}
33
}
Copied!
Have a detailed look at the require keyword, which now requires both the Shopware 6 version, which always has to be mentioned in your composer.json, as well as the previously mentioned plugin and its version. Just as in composer itself, you can also use version wildcards, such as v1.0.* to only require the other plugin's minor version to be 1.1, not taking the patch version into account when it comes to find the matching plugin version.
Now your plugin isn't installable anymore, until that requirement is fulfilled.

More interesting topics

Last modified 6mo ago