A plugin is the main way to extend your Shopware 6 instance programmatically.
Plugins in Shopware are essentially an extension of Symfony bundles. Such bundles and plugins can provide their own resources like assets, controllers, services or tests. A plugin is the main way to extend your Shopware 6 instance programmatically. All you need for this guide is a running Shopware 6 instance and full access to both the files, as well as the command line. Of course you’ll have to understand PHP, but that’s a prerequisite for Shopware as a whole. First, you need to find a name for your plugin. We’re talking about a technical name here, so it needs to describe your plugins functionality as short as possible. By convention it is written in UpperCamelCase. To prevent issues with duplicated plugin names, you should add a shorthand prefix for your company. Here at Solution25 we’ll be using “Sol” as a prefix for that case. For this example, guide we’ll use the plugin name SolBasicExample. Now that you’ve found your name, it’s time to actually create your plugin.
The absolute bare minimum for a functional plugin can be obtained by using the following command: php/bin/console plugin:create SolBasicExample Now, go to Admin and select Settings > System > Plugins, where the new plugin SolBasicExample is listed. The command will then create a directory, named SolBasicExample, in your custom/plugins directory. It will also generate a subdirectory structure, that contains the composer.json, SolBasicExample.php and services.xml file. The only thing missing for your plugin to be fully functional, is a composer.json file inside your plugin’s root directory. custom/plugins/SolBasicExample/composer.json This file consists of basic information, that Shopware needs to know about your plugin, such as: This file consists of basic information, that Shopware needs to know about your plugin, such as:
This file consists of basic information, that Shopware needs to know about your plugin, such as: ● The technical name ● The description ● The author ● The used license ● The current plugin version ● The required dependencies
This file can also be read by Composer, but that’s not part of this guide. Further information you’ll have to add in there: The type has to be Shopware-platform-plugin, so Shopware can safely recognize your plugin as such and the require field must include at least shopwarecore, to check for compatibility. If you go to the Administration now, you can see the plugin in the Extensions where you can perform the installation, or you can safely install your plugin via your command line terminal and navigate to your Shopware 6 directory, the one which also contains the custom directory.Once inside there, you need to refresh the list of plugins, that Shopware knows yet. This is done with the following command:php/bin/console plugin:refresh
This output is a good sign, because this means Shopware recognized your plugin successfully. But it’s not installed yet, so let’s do that. php/bin/console plugin: install –activate SolBasicExample
It should look something like this! xml version=”1.0″ encoding=”UTF-8″? config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” noNamespaceSchemaLocation=”https://raw.githubusercontent.com/shopware/platform/master/src/Core/System/SystemConfig/Schema/config.xsd” title>SolBasicExample settings</title If you want to know more about e-commerce development platforms or apps, read our blog posts for Shopify and Shopware. Our dedicated outsourcing team can be your collaborator in ecommerce.