Since version 1.7 of PrestaShop, everyone have access to the PrestaShop console using the following instruction in a terminal:

./bin/console # or ./app/console for PrestaShop < 1.7.3

Since v1.7.5, you can add and provide your own commands into the PrestaShop console using modules.

Let’s see an example of a really common task when we usually use CRON scripts: you want to export your products into an XML file in order to import them into an another platform (a PIM or an ERP).

You could rely on the webservices, but they are not really easy to configure. This is how you can do it using a PrestaShop command.

Create a command into the module

You need to create the file and register it as a “command”.

Setup composer

You need setup composer in your module before create the command. Create the file your-module/composer.json and paste:

    "name": "<your name>/<nmodule name>",
    "description": "<module description>",
    "authors": [
            "name": "<your name>",
            "email": "<your email>"
    "require": {
        "php": ">=5.6.0"
    "autoload": {
        "psr-4": {
            "<YourModule>\\": "src/"
        "exclude-from-classmap": []
    "config": {
        "preferred-install": "dist"
    "type": "prestashop-module",
    "author": "<???>",
    "license": "<???>"

In YourModule add your namespace. Then in console in your module root run command composer dump-autoload.

Creation of the command

At this moment, the only requirement is that you PHP file needs to be a class that extends Symfony\Component\Console\Command. Let’s create ExportCommand file:

// your-module/src/Command/ExportCommand.php
namespace YourNamespace\Command;

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

class ExportCommand extends Command
    protected function configure()
        // The name of the command (the part after "bin/console")

    protected function execute(InputInterface $input, OutputInterface $output)
        // Here your business logic.
        $output->write('Export done!');

Registration of the command

Now, in order to make this really simple command available in the console, we register it in the services.yml file:

# your-module/config/services.yml
        class: YourModule\Command\ExportCommand
            - { name: 'console.command' }

The command should be now available using ./bin/console your-module:export.

Learn more about the PrestaShop Console

We use the Symfony Console with nothing specific to PrestaShop.

You can learn everything about this component in their documentation in version 3.4.

To sum up, there is a list of useful links: