Shopware 6 - Tips, tricks and how to's

The most useful commands for Shopware 6 development

Because Shopware 6 is based on the Symfony framework, it also has its Console available. Yes, you can do most of the stuff, that you need to do, while developing the Shopware 6 plugins, in the Administration. However, with the Console, it is sometimes faster, especially bulk operations like deactivating multiple plugins at once etc. And when you need to automate things, for example for deployment to production server, then the console commands are the only reasonable option. So let us take a look at the console and the standard commands at our disposal.

How to use the Shopware 6 console

To be able to use the console commands, you have to run it in your favorite command line software, for example Putty or the bulit-in SSH client in PhpStorm. When you have connected, first navigate the the root directory of your Shopware 6 installation. You can use the “ls” command to see, where in the directory structure you currently are and the “cd” command to move to the directory you need. If you need to go back one level, you just write “cd ..” to the command line and press enter.

With this information, you should be able to comfortably navigate to the Shopware 6 store root directory. It contains the “bin” directory and in it is the “console” file. However, you do not need to navigate to that subdirectory – the standard way of using the Console is to call it from the SW6 root like this:

This way, you have called the console without any command, so it gives you a list of the commands, that are available to you. You will find the standard Symfony and Shopware 6 commands in here, but also custom commands from the plugins, that have been installed and are active. In this article, we will be focusing on the standard commands, so we will demonstrate, how to use the console commands on the one, that is probably used most often from them all – the clear cache command:

This command, however, does not have any additional parameters, so here comes one more quick example:

If you need to pass an argument to a command, you just put a space after it and then simply write the argument. Multiple arguments can be passed similarly, always after space. If your argument is a text with spaces, you have to encapsulate it in apostrophes. And that is it, after this small tutorial, you know the basics of working with the Console!

The list of the most useful Shopware 6 commands

So now that we know, how to work with Console, here comes the list of the commands, commonly used during Shopware 6 plugin development:

Clear the cachecache:clear
List all pluginsplugin:list
Create a plugin skeletonplugin:create
Install plugin(s)plugin:install
Uninstall plugin(s)plugin:uninstall
Activate plugin(s)plugin:activate
Deactivate plugin(s)plugin:deactivate
Update plugin(s)plugin:update
Create a theme skeletontheme:create
Compile the themetheme:compile
Create an admin useruser:create
List available servicesdebug:container
The list of the most useful Shopware 6 commands

If you want to see the parameters, that these commands accept, you can safely run them with -h, without really doing anything:

Now follows some additional information on the fore mentioned commands, that you might find useful.

Clear the cache

This is a very useful command, and one, that actually makes it worth to keep your console window open. 😉 Even in development environment, it is very useful to clear the cache after making some changes, especially on the frontend and when you feel like they have no impact. It is the equivalent of this function from the Shopware 6 backend:

List all plugins

This command will give you a list of plugins, that contains their current state, version nad other basic data.

Create a plugin / theme skeleton

This command will ask you for the basic information for your new plugin or theme and then will generate the directory structure and files for it. Easy peasy.

Install, uninstall, activate, deactivate and update a plugin(s)

Using these commands, you can easily perform the desired action with or more plugins. You can just put their names one after another, separated by spaces. Plugin names, accepted by this command, can be found in the database table, named “plugin”, in the column “name”. I also wrote an article on how to work with the plugin names efficiently, so check that out, if your store contains a lot of plugins.

When using these commands, you do not have to worry about the current state of the plugins, the command will skip those, that are already in the target state or will throw you a message, explaining why their state could not be changed (for example you can not activate a plugin, that has not been installed yet).

You could also perform these operations in the Plugin list screen in the Administration, but doing it in the console has several advantages. First of all, it is faster. And the more plugins you have, the faster it is. Secondly, in contrast with the disappearing message, that you get from the Administration page, the console has a more detailed output, that stays there. That is very useful for debugging your plugin installation processes, as I have found out during solving the inaccessible classes problem.

Compile the theme

This command is needed, when you do some changes in your theme plugin, especially regarding javascript.

Create an admin user

This command is the way to create a new Admin account for the backend of your Shopware 6 store.

List available services

This command gives you a list of the services, that are currently present in your Shopware 6 installation. That is useful for many purposes, for example when you want to make sure, that your service is registered properly or when you are trying to figure out, why some other service is not available. You can either run this command without any parameters to obtain a complete list of services, or specify a service, that you are looking for. Be sure to check out other options as well, there is plenty of them.

Useful scripts, that are not part of the Console

Besides the standard Console commands, there are also shell scripts, that you might need, especially when you are creating modules for Shopware 6 backend. It is based on Vue.js javascript framework, so depending on your setup, sometimes it si necessary to perform a “build” operation before your changes are actually visible. The shell scripts for this are also located in the bin subdirectory of your Shopware 6 root directory and you can run them like this:

Here is a list of the most useful shell commands for Shopware 6:

Build frontendbuild-storefront.sh
Build backendbuild-administration.sh
Build bothbuild-js.sh
The list of most useful Shopware 6 shell commands