Creating commands via plugin


Creating a command for Shopware 6 via a plugin works exactly like you would add a command to Symfony. Make sure to have a look at the Symfony commands guide.

Registering your command

The main requirement here is to have a services.xml file loaded in your plugin. This can be achieved by placing the file into a Resources/config directory relative to your plugin's base class location. Make sure to also have a look at the method getServicesFilePath

From here on, everything works exactly like in Symfony itself.

Here's an example services.xml which registers your custom command:

<?xml version="1.0" ?>

<container xmlns=""

        <service id="Swag\PluginCommands\Command\ExampleCommand">
            <tag name="console.command"/>

And the related example command:

<?php declare(strict_types=1);

namespace Swag\PluginCommands\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ExampleCommand extends Command
    protected static $defaultName = 'plugin-commands:example';

    protected function execute(InputInterface $input, OutputInterface $output)
        $output->writeln('Do something...');

In this example, it would be located in the directory <plugin root>/src/Command. After installing, you can now execute your command by running this command: bin/console plugin-commands:example

Make sure to read the full guide about Symfony commands to understand, how to deal with commands and how they can be configured.


There's a GitHub repository available, containing this example source. Check it out here.

Was this article helpful?

Version or newer