Table of Contents

Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.

You might want to look at the current version, PrestaShop 8. Read the updated version of the documentation

Learn how to upgrade to the latest version.

Modules FAQ

Q: How do I add a command to an existing module with autoloading?

A: In the modules section of the documentation, about module commands, the instructions assume the module is installed via Composer. If you follow the same procedure but wish to add the command in your existing module in modules/<module_directory>, then the procedure requires an extra step.

For example, with a structure like this:

├── config
│   └── services.yml
├── config.xml
├── module_directory.php
├── src
│   └── Command
│       └── SyncCommand.php

You would also need to namespace your src directory in composer.json located in the base directory of your project, by appending the following:

    "autoload": {
        "psr-4": {
            "PrestaShop\\PrestaShop\\": "src/",
            "PrestaShopBundle\\": "src/PrestaShopBundle/",
            "Vendor\\Module\\": "modules/module_directory/src/"
        "classmap": [

And follow through using the correct namespaces throughout your module commands.

Predefined Constants: If you would like to use existing PS constants like _DB_PREFIX_, you also need to require the file config/


$basePath = realpath(__DIR__ . '/../../../../');
require_once $basePath . '/config/';

Loading Module Classes: Commands, by default, won’t have module classes loaded. You must require the module’s main file before using their classes.


require_once _PS_MODULE_DIR_ . '/<module_directory>/<module_directory>.php';