We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
How to Create a Plugin in "Shopware 6"?
Shopware 6 offers a variety of plugins in addition to the shop system, which you can purchase from the store. This allows you to personalize your Shopware store and add new features. The installation & activation of these plugins is the focus of this blog.
All plugins are handled through the Shopware6 Plugin Manager, which can be found in your backend under the menu item "Settings". You may quickly and simply buy, download, install, and activate the Shopware 6 plugins there.
This is a very basic tutorial that will guide you through the process of creating a Shopware 6 plugin in the easiest way possible. There are more ways to create plugins, and if you want to learn more about them, go to the official documentation and read everything there: Base Guide for Plugins.
You may use any name for plugins, but for organization purposes, it is suggested to use manufacturer + technical name. Some examples are as follows
- Manufacturer+TechnicalName
- YourCompany+HelloWorld
- BankName+APIintegration
You may name your plugin whatever you like. We will go with MageSparkHelloWorld
Steps to create Plugin in Shopware 6:
#step1: Create A Plugin Skeleton
Open your Shopware installation directory in CLI. then you can follow the following steps.
Apply the following command:
php bin/console plugin:create MageSparkHelloWorld
In the custom/plugins/MageSparkHelloWorld folder, Shopware will develop a basic structure for you. See the following documents:
custom/plugins/MageSparkHelloWorld ├── composer.json └── src ├── MageSparkHelloWorld.php └── Resources └── config └── services.xml
Important Please edit the composer.json file to look like the following example. Otherwise, it will not function. Focus on the following lines that have been highlighted:
composer.json
{ "name": "magespark/hello-world", "description": "This plugin is created by MageSpark to describe the plugin creation in Shopware 6", "type": "shopware-platform-plugin", "license": "MIT", "authors": [ { "name": "MageSpark", "homepage": "https://www.magespark.com" } ], "autoload": { "psr-4": { "MageSpark\\HelloWorld\\": "src/" } }, "extra": { "shopware-plugin-class": "MageSpark\\HelloWorld\\MageSparkHelloWorld", "label": { "de-DE": "MageSpark - Hallo Wereld!", "en-GB": "MageSpark - Hello World!" } } }
Keep in mind that the type "shopware-plugin-class" is how Shopware knows you have a plugin in that directory. It shouldn't operate without this reference.
Please change the MageSparkHelloWorld.php file to look like the following example, else it will not work. Pay close attention to the highlighted lines:
MageSparkHelloWorld.php
<?php declare(strict_types=1);
namespace MageSpark\HelloWorld;
use Shopware\Core\Framework\Plugin;
class MageSparkHelloWorld extends Plugin
{
}
This is the services.xml file's content. By default, This file does not need to be updated. But, if your plugin classes depend on other services you will have to define the dependency in this file.
services.xml
<?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> </services> </container>
Here, we have completed the basic structure of our first plugin. Now, Our plugin is ready for installation.
#step2: Install & Activate the Plugin
Execute the following, In the command line:
php bin/console plugin:refresh
This command will refresh the plugin list. So your plugin list will now updated with newly added plugin. You will get results like the following:
Let's install and activate our plugin now that it's been loaded. Execute the following code:
php bin/console plugin:install --activate MageSparkHelloWord
The above command will install and activate your plugin at the same time. But, If you wish to just install the plugin, you can do it by the following command
php bin/console plugin:install MageSparkHelloWorld
And then to activate the plugin letter, you can use the following command. Of Course you can activate the plugin from the backend too.
php bin/console plugin:activate MageSparkHelloWorld
You should have gotten something like this
That's all! You're done creating & installing your Shopware 6 plugin!
We have not written any code to customize the website. So, you will not be able to see any change in the front end. But you can see this plugin at the backend settings -> My Extensions menu.
I hope this Shopware 6 plugin tutorial helped you gain knowledge. If you have any questions or discover any issues, please post them in the comments box below. We'd be delighted to assist you with this.
Remember to share this solution with your Shopware community or friends on social media, and stay tuned for future Shopware 6 tech tutorials.
Also, if you want to Develop Your Shopware Plugins do contact our certified shopware experts.
Have fun coding!!