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.
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:
<?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:
...
"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.
<?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.
Last updated