Thursday, May 13, 2021
Home E-Commerce Prestashop 1.5 features for developers (Part-1 Modules)

Prestashop 1.5 features for developers (Part-1 Modules)

PrestashopUntil this writing, Prestashop 1.5.2 is current stable release. In this article series we will only discuss the new features, APIs and other techniques available for Prestashop developers.  How the system is working and how the classes, controllers and admin control panel is organized code wise. Also we will discuss the new modules structure. A features introduction for normal users can be found here .

Prestashop Modules API : The new modules API is very comprehensive, easy to use and lots of more features are available now.  New hooks are created for modules, and some hooks are renamed to more suitable names. A complete list of the Hooks can be found here. Thanks to Prestashop 1.5 new modules API we can also use a complete MVC structure for the Modules,  which has controllers , Models and Views in separate folders, as can be seen in below picture.

Prestashop 1.5 MVC module structure
Prestashop 1.5 MVC module structure

In the picture an Faq test module for Prestashop 1.5 is shown. The Controllers folder can have two more sub folders, front and admin. The front folder will have all the controllers needed for the front end of the module. The admin folder will have all controllers needed for the admin purpose. Please note that before Prestashop1.5, we were placing the admin controllers needed for a module in the /admin-folder/tabs/ folder. But in Prestashop 1.5 , the admin tabs files are converted to controllers and are placed in the /controllers/admin/ folder, and hence the override feature is also available for admin tabs. Override files are placed in /override/controllers/admin/ folder.

If you need a tab at admin which has to be linked to a module, then for this purpose we place the controller for the admin tab in the /faq/controllers/admin/ folder. Hence a powerful MVC feature is provided and almost all of our module files will be in the module folder. . The models folder will have the class associated with the admin controller and if needed any other classes. Please note that if you are using MVC for the module, and placed your class in models folder, then you have to include that class at the top of your module main class, in our example faq.php.

Now lets consider that we have a module “faq” as shown in the above picture, and we  want to create a front controller for the module and controller name will be “faqs“which will be displaying list of the Faqs at front end. So we will first create a php file called “faqs.php” in the /faq/controllers/front/.  Now here for front end the controller class can be created by using the following method.


So our faqcontroller class will be like

class FaqFaqsModuleFrontController extends ModuleFrontController





Please note that the controller class is extended from ModuleFrontController class.

Now lets consider we want to create a controller for the admin section, it is a little bit different. Lets say we want the controller to be AdminFaqController, so place a file in the /faq/controllers/admin/ and name is AdminFaqController.php . So the class code will be like

class AdminFaqController extends ModuleAdminController





Note that the admin controller class is started same as the old versions, but only difference is that we extend it now from ModuleAdminController class.

The Views folder will have all template files. It has a sub folder called “templates”. Currently as i know (and also I used), there are two sub folders in templates, “hooks” and “front”. As the names are showing, the hooks folder will have all the template files used with the hooks at which the module is transplanted, and the front folder will have all the template files used for the front controllers (placed in the /controllers/front/ folder) for the module.

Here you can read how to create a Prestashop 1.5 module.

In the next post we will discuss about the front end controllers in Prestashop 1.5.

- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....