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
  • composer.json file
  • Create a plugin base class
  1. Bundles
  2. Plugins and AdditionalBundles

Create plugin

PreviousPlugins and AdditionalBundlesNextAdd additional bundles

Last updated 1 month ago

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:

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:

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:

composer.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"
        }
    }
}

As you can see we already registered a plugin base class in the extra-section. But this class does not exist yet.

Create a plugin base class

FooBar/FooBar.php
<?php

namespace Foo\Bar;

use Dustin\ShopwareUtils\Core\Framework\Plugin;

class FooBar extends Plugin
{
}

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.

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:

Plugin Base Guide | Shopware Documentation
Plugin Base Guide | Shopware Documentation
Logo
Logo
The complex way - Integrate into your plugin