This article will be useful to those who want to learn how to create their first module for cms PrestaShop and understand how to display information in the hooks of an online store template.

To create a skeleton of a new module, we need to go to a special site for developers Generator Prestashop Module. This resource generates the skeleton of a new module.

The first page of the module generator

Briefly about the points to fill out on the first page:

Module type – choice specifications Your his module (general, module delivery, module payment, and т. д.);

Module tab – module category (will be displayed in the admin panel on the modules tab in the category that you select);

Module name – this is the unique name of the module (equivalent to id);

Display name – this is the name of the module, public and main;

Description – description of your module;

Author – module author

Version – version of the module.

After filling in all the information, click on the next button.

2nd stage of module generation for PrestaShop

Briefly about the points of stage 2:

Confirm uninstall – add a notification that when the module is removed, all data will be lost;

Create default database table – Create default database table – add database table settings;

Need instance – whether it is necessary to load the main class of the module on the “modules” tab;

Compliancy min – compatibility with the minimum version of the module;

Compliancy max – compatibility with the maximum version of the module;

Step 3 has only one item – this is the choice of the information output hook.

We choose the simplest hook – this is the output on the main page in the content part.

After clicking on the create button, the start archive of the module is downloaded to your computer.

Further on previously established

After clicking on the create button, the start archive of the module is downloaded to your computer.

Further on previously established сms PrestaShop in the admin panel at Modules> Module Manager, click on the “install module” button, as in the screenshot:

Installing the PrestaShop module

Let’s load our created archive of the new module, then we need to open the main file of our module via FTP at modules/modulename/modulename.php.

Hooks – this is the output of a block at a certain place in the online store.

When installing a module, a hook is registered in the install() method.

$this->registerHook(‘displayHome’);

A non-static public method with the “hook” keyword will be created in the main class of the module

In this method, using the return statement, we can return a value, and it will be displayed on the main page in the content part.

For example, let’s print the html in this method. To do this, create a new file namefile.tpl under the path views/templates/hook/ (if there are no necessary folders, then create them).
In the file, create the required html markup and add an output line to the method.

display(local_path, ‘views/templates/hook/namefile.tpl’); }

That’s all. This article is needed to understand the creation and operation of modules on cms PrestaShop.

Our website

Our forum

Official documentation

If you have any questions, ask them in the comments or at our forum.