Add custom CLI commands
To ease development tasks, Shopware contains the Symfony commands functionality. This allows (plugin-) developers to define new commands executable via the Symfony console at
bin/console. The best thing about commands is, that they're more than just simple standalone PHP scripts - they integrate into Symfony and Shopware, so you've got access to all the functionality offered by both of them.
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:
This guide does not explain how to create a new plugin for Shopware 6. Head over to our plugin base guide to learn how to create a plugin at first:
The main requirement here is to have a
services.xmlfile loaded in your plugin. This can be achieved by placing the file into a
Resources/configdirectory relative to your plugin's base class location.
From here on, everything works exactly like in Symfony itself. Commands are recognised by Shopware, once they're tagged with the
console.commandtag in the dependency injection container. So to register a new command, just add it to your plugin's
services.xmland specify the
<!-- ... -->
<!-- ... -->
Here's a full example
services.xmlwhich registers your custom command:
<?xml version="1.0" ?>
Your command's class should extend from the
Symfony\Component\Console\Command\Commandclass, here's an example:
class ExampleCommand extends Command
// Command name
protected static $defaultName = 'swag-commands:example';
// Provides a description, printed out in bin/console
protected function configure(): void
$this->setDescription('Does something very special.');
// Actual code executed in the command
protected function execute(InputInterface $input, OutputInterface $output): int
// Exit code 0 for success
This command is of course only a basic example, so feel free to experiment. As stated above, you now have access to all the functionality offered by Symfony and Shopware.
Commands are run via the
bin/consoleexecutable. To list all available commands, run
$: php bin/console list
Symfony 4.4.4 (env: dev, debug: true)
command [options] [arguments]
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-e, --env=ENV The Environment name. [default: "dev"]
--no-debug Switches off debug mode.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
about Displays information about the current project
help Displays help for a command
list Lists commands
feature:dump [administration:dump:features] Creating json file with feature config for js testing and hot reloading capabilities.
bundle:dump [administration:dump:plugins|administration:dump:bundles] Creates a json file with the configuration for each active Shopware bundle.
cache:clear Clears the cache
cache:pool:clear Clears cache pools
cache:pool:delete Deletes an item from a cache pool
cache:pool:list List available cache pools
cache:pool:prune Prunes cache pools
cache:warmup Warms up an empty cache
Each command usually has a namespace like
cache, so to clear the cache you would execute
php bin/console cache:clear. If you'd like to learn more about commands in general, have a look at this article in the Symfony documentation.