dustin/shopware-utils
  • dustin/shopware-utils
  • Installation
    • Installation
  • Bundles
    • Plugins and AdditionalBundles
      • Create plugin
      • Add additional bundles
    • Themes
  • Migrations
  • Features
    • Configuration
  • Adding resources
    • Custom fields
    • Document types
    • Payment methods
    • Mail template types
    • Mail templates
Powered by GitBook
On this page
  • Create a subdirectory
  • Create a bundle base class
  • Register namespace
  • Create a bundle object
  • Refresh plugins
  1. Bundles
  2. Plugins and AdditionalBundles

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.

If your AdditionalBundle provides a theme the name of the subdirectory must be identical to the name of the bundle!

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:

FooBundle/FooBundle.php
<?php

namespace Foo\Bundle;

use Dustin\ShopwareUtils\Core\Framework\AdditionalBundle;

class FooBundle extends AdditionalBundle
{
}

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:

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

Create a bundle object

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

FooBar/FooBar.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()
        ];
    }
}

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.

PreviousCreate pluginNextThemes

Last updated 1 month ago