> For the complete documentation index, see [llms.txt](https://dustinsimon.gitbook.io/shopware-utils/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dustinsimon.gitbook.io/shopware-utils/bundles/plugins-and-additionalbundles/add-additional-bundles.md).

# Add additional bundles

dustin/shopware-utils allows you to create plugin-like bundles and integrate them in your main plugin. AdditionalBundles can be considered inner plugins with their own namespace, installation steps and resources, just like a normal plugin.

## **Create a subdirectory**

Just like the main plugin an AdditionalBundle needs it's own subdirectory within your plugin directory.&#x20;

{% hint style="info" %}
If your AdditionalBundle provides a theme the name of the subdirectory must be identical to the name of the bundle!
{% endhint %}

Let's assume our bundle will be named *FooBundle* we also name the subdirectory *FooBundle*.

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

## **Create a bundle base class**

Equally to plugins each bundle needs a base class:&#x20;

{% code title="FooBundle/FooBundle.php" %}

```php
<?php

namespace Foo\Bundle;

use Dustin\ShopwareUtils\Core\Framework\AdditionalBundle;

class FooBundle extends AdditionalBundle
{
}
```

{% endcode %}

Your plugin directory structure now should look like this:

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

## **Register namespace**

Your new bundle namespace must be registered in your plugin's *composer.json* file. Add a new key to the *autoload*-section:

{% code title="composer.json" %}

```json
...
"autoload": {
    "psr-4": {
        "Foo\\Bar\\": "FooBar/",
        "Foo\\Bundle\\": "FooBundle/"
    }
}
...
```

{% endcode %}

## **Create a bundle object**

Each AdditionalBundle has to be created within your plugin base class. Overwrite the `createAdditionalBundles`-method.

{% code title="FooBar/FooBar.php" %}

```php
<?php

namespace Foo\Bar;

use Foo\Bundle\FooBundle;
use Dustin\ShopwareUtils\Core\Framework\Plugin;

class FooBar extends Plugin
{
    protected function createAdditionalBundles(): array
    {
        return [
            new FooBundle()
        ];
    }
}
```

{% endcode %}

## Refresh plugins

If you have created a new AdditionalBundle you need to execute the `plugin:refresh` console command or reload the plugin list in Shopware administration. This is neccessary to update the autoload-section of your plugin which is stored in database.
