Plugins in Shopware are basically an extension of Symfony bundles. Plugins can give their own resources like assets, controllers, services, or tests. To create a plugin in shopware 6 follow the below instructions.
First, you need to connect the SSH of your shopware site. If you run the below command it will show all the available commands in shopware.
bin/console
Now to create a plugin by running the below command and you need to add the technical name of your plugin. To describe your plugin’s functionality as short as possible, write in UpperCamelCase. To prevent issues with duplicated plugin names, you should add a shorthand prefix for your company.
Shopware uses “Swag” as a prefix for that case.
bin/console plugin:create SwagCustomplugin
SwagCustomplugin is the name of our plugin. The plugin directory is custom/plugins.
In the src directory, there is a PHP class named after the plugin (SwagCustomplugin.php). This new class SwagCustomplugin
has to extend from Shopware’s abstract Plugin class, which is Shopware\Core\Framework\Plugin
. The below code will be on the SwagCustomplugin.php file.
<?php declare(strict_types=1);
namespace SwagCustomplugin;
use Shopware\Core\Framework\Plugin;
class SwagCustomplugin extends Plugin
{
}
The composer.json file consists of basic information, that Shopware needs to know about your plugin, such as:
- technical name
- description
- author
- used license
- current plugin version
- required dependencies
The below code will be in the composer.json file. The type has to be shopware-platform-plugin, so Shopware can safely recognize your plugin and the required field must include at least shopware/core, to check for compatibility.
{
"name": "swag/plugin-skeleton",
"description": "Skeleton plugin",
"type": "shopware-platform-plugin",
"license": "MIT",
"autoload": {
"psr-4": {
"SwagCustomplugin\\": "src/"
}
},
"extra": {
"shopware-plugin-class": "SwagCustomplugin\\SwagCustomplugin",
"label": {
"de-DE": "Skeleton plugin",
"en-GB": "Skeleton plugin"
}
}
}
This is the basic structure and all necessary files for your plugin.
Please contact us at manish@bay20.com or call us at +91-8800519180 for any support related to shopware. You can also visit the Shopware development page to check the services we offer.