Until 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.
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.