# Create plugin

This guide shows you how to create a new plugin.\
It's a good choice to visit Shopware's documentation first if you are not familar with Shopware plugins:&#x20;

{% embed url="https://developer.shopware.com/docs/guides/plugins/plugins/plugin-base-guide.html" %}

## **Create a subdirectory**

In your plugin directory create a new sub-directory which will be the source directory of your main plugin. Name it whatever you want. The name should be meaningful and describe the main functionality of your plugin. It's a good choice to use the name of the plugin as directory name:

**\<plugin-dir>**\
**|— FooBar/**

## **composer.json file**

We now have to create a plugin _composer.json_ file. You can take a look at the Shopware documentation about the contents of the file:

{% embed url="https://developer.shopware.com/docs/guides/plugins/plugins/plugin-base-guide.html#the-composer-json-file" %}

The important part of the _composer.json_ file is the _autoload_-section. Make sure your plugin namespace links to the subdirectory created before.

The example plugin "Bar" from the "Foo"-company would look like this:

**\<plugin-dir>**\
**|— FooBar/**\
**|— composer.json**

The _composer.json_ file could look like this:

{% code title="composer.json" %}
```json
{
    "name": "foo/bar",
    "description": "Demo-Plugin",
    "type": "shopware-platform-plugin",
    "autoload": {
        "psr-4": {
            "Foo\\Bar\\": "FooBar/"
        }
    },
    "require": {
        "dustin/shopware-utils": "~1.0"
    },
    "extra": {
        "shopware-plugin-class": "Foo\\Bar\\FooBar",
        "label": {
            "de-DE": "Demo-Plugin",
            "en-GB": "Demo plugin"
        }
    }
}
```
{% endcode %}

As you can see we already registered a plugin base class in the _extra_-section. But this class does not exist yet.&#x20;

## **Create a plugin base class**

{% code title="FooBar/FooBar.php" %}
```php
<?php

namespace Foo\Bar;

use Dustin\ShopwareUtils\Core\Framework\Plugin;

class FooBar extends Plugin
{
}
```
{% endcode %}

{% hint style="info" %}
Note that we do not inherit from the typical Shopware Plugin-class but from `Dustin\ShopwareUtils\Core\Framework\Plugin`_._\
This is important for using features like automatic custom field installation and more.
{% endhint %}

{% hint style="info" %}
If you have installed dustin/shopware-utils directly in your plugin, you also have to overwrite the `createAdditionalBundles`-method and return a _ShopwareUtils_-object. For more details take a look at here: [#the-complex-way-integrate-into-your-plugin](../../../installation/installation#the-complex-way-integrate-into-your-plugin "mention")
{% endhint %}
