Child pages
  • Creating a PrestaShop module

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

PrestaShop's extensibility revolves around modules, which are small programs that make use of PrestaShop's functionality and changes them or add to them in order to make PrestaShop easier to use or more customized.

Technical principles behind a module

A PrestaShop module consists of:

  • A root folder, named after the module, which will hold all of the module's files, and will reside in PrestaShop's /modules folder.
  • A main PHP file, named after the module, located in that root folder. This PHP file should have the same name as its root folder.
  • Two icon files representing this module in the back-office.
    • One file for PrestaShop 1.4: logo.gif, 16*16 pixels.
    • One file for PrestaShop 1.5: logo.png, 32*32 pixels.
  • Optional: some template files .tpl files, containing the module's theme.
  • Optional: language files, if the module or its theme have text to display (and therefore, text that should be translated).
  • Optional: in a /themes/modules folder, a folder with the same name as the module, containing .tpl and language files if necessary. This last folder is essential during modifications of existing module, so that you can adapt it without having to touch its original files. Notably, it enables you to handle the module's display in various ways, according to the current theme.

...

TODO: multiboutique: module par boutique, voire hook par boutique

Modules' operating principles

Modules are the ideal way to let your talent and imagination as a developer express themselves, as the creative possibilities are many.

...

One of the main interest of a module is to add functionalities to PrestaShop without having to edit its core files, thus making it easier to perform an update without having the transpose all core changes. Indeed, you should always strive to stay away from core files when building a module, even though this can prove hard to do in some situations...

Module file tree

PrestaShop's modules are most often found in the /modules folder, which is at the root of the PrestaShop main folder. This is true for both default modules (provided with PrestaShop) and 3rd-party modules that are subsequently installed.
Modules can also be part of a theme if they are really specific to it. In that case, they would be in the theme's own /modules, and there under the following path: /themes/mytheme/modules

...

On installation, PrestaShop also adds a line to the ps_module SQL table.

Hooking a module

Displaying data, starting a process at a specific time: in order for a module to be "attached" to a location on the front-office or the back-office, you need to give it access to one of the many PrestaShop hooks, described earlier in this guide.

...

Save. The "Positions" page should reload, with the following message: "Module transplanted successfully to hook". Congratulations! Scroll down, and you should indeed see your module among the other modules from the "Left column blocks" list. Move it to the top of the list.

Displaying content

Now that we have access to the left column, we should display something there.

...

Tip

If you make multiple changes and reloads to your homepage, it may seem said changes do not apply. This is because Smarty caches a compiled version of the homepage. In order to force Smarty to recompile templates on every invocation, you must go to "Preferences" tab, its "Performance" sub-tab, and choose "Yes" for the "Force recompile" option.

Do not force recompilation on production sites, as it severely slows everything down!

Using Smarty

Smarty is a PHP template engine, and is used by PrestaShop's theming system.

...