Book Image

Practical Module development for Prestashop 8

By : Louis AUTHIE
Book Image

Practical Module development for Prestashop 8

By: Louis AUTHIE

Overview of this book

After version 1.7, PrestaShop underwent a host of changes, including migration to a Symfony-based system from an outdated legacy code. This migration brought about significant changes for developers, from routine maintenance to module development. Practical Module Development for PrestaShop 8 is curated to help you explore the system architecture, including migrated and non-migrated controllers, with a concise data structure overview. You’ll understand how hooks enable module customization and optimize the CMS. Through the creation of seven modules, you’ll learn about the structure of modules, hook registration, the creation of front-office controllers, and Symfony back-office controllers. By using Doctrine entities, services, CQRS, grids, and forms, you’ll be guided through the creation of standard, payment and carrier modules. Additionally, you'll customize and override themes to achieve your desired e-commerce store look. By the end of this book, you’ll be well equipped to provide modern solutions with PrestaShop that meet client requirements.
Table of Contents (23 chapters)
1
Part 1 – Understanding How PrestaShop is Structured and How It Works
8
Part 2 – How to Create Your Own Modules
16
Part 3 – Customizing Your Theme
Appendix – Module Upgrade, The Hooks Discovery Tool, and Multi-Store Functions

The core classes – how the MVC works

Let’s explore how pages are generated by PrestaShop. Don’t worry if you think that we won’t go deep enough into how everything works; we want to stay in a high-level point of view to get a full picture of the system. In Chapters 3 and 4, we will be more technical!

FO and BO pages are automatically generated by the core of PrestaShop. As with many existing CMSs, PrestaShop uses a custom PHP framework that was improved following the versions. This original framework built from the beginning to version 1.7.x.x is called the legacy core by the developers of the PrestaShop community. It is still improving to cope with the immediate needs of users, but the choice was made by the core developers to move to a new framework based on Symfony.

As it is a strong and efficient framework, it can take care of all the main generic needs of the system, such as security, database handling, and forms generation, and all the most useful tools it provides. It should enable the PrestaShop community to focus on e-commerce-specific needs.

Presenting the legacy core MVC pattern

The legacy core is based on an MVC pattern. If you don’t know this famous design pattern, just remember that each page is generated by a PHP Controller. It uses a Model Object to retrieve or modify data in the database and takes care of all computation and data processing to provide it to a View template. This View template is responsible for the graphical aspect of the page.

It enables the different actors of a project not to interfere. The developers can work on the controller while data managers can take care of the model and the integrators build the views. This way, you can also change each tier of the structure without changing others. Here is a diagram illustrating the same:

Figure 1.2 – The legacy core MVC design pattern

Figure 1.2 – The legacy core MVC design pattern

As presented in Figure 1.2, the Controller calls Object Model(s) to get or manipulate the data, processes it, and sends it to a View template to generate a final view.

\What is the legacy core?

As it is not obvious, the legacy core is a set of PHP classes that are part of the PrestaShop framework. They are mainly stored in the /classes and /controllers folders.

Discovering the core migration

As we have seen before, a migration from the old legacy core to a Symfony-based one is in progress. This migration started with the BO pages and will end with the FO pages. The FO migration will start when the BO has fully migrated. That’s the reason why some BO pages are still using the legacy core MVC and some others use the new Symfony design. All FO pages still use the legacy core before and in the v8.0 release.

You can discriminate which BO pages are migrated by watching their URLs: those containing /index.php?controller=Admin are not migrated yet, and those containing /index.php/ are migrated.

The Symfony migrated pages also use an MVC structure, but they follow the Symfony way of coding by using a different templating engine. Even if Symfony is made to use Doctrine and its entities to manipulate the data, during the migration process, we will still use the ObjectModel child objects we have seen before. The new core of PrestaShop is being built into the /src/ folder. We will see in Chapter 4, The Back Office, how this can be done.

In the following diagram, you will find a summary of how the different pages can be managed during the migration of PrestaShop from Legacy Core to Symfony Core:

Figure 1.3 – How things work during the migration process

Figure 1.3 – How things work during the migration process

The aim of the migration process is to remove Legacy Core and make every page of PrestaShop generated by Symfony Core, as illustrated in the following diagram:

Figure 1.4 – How things will work after the migration process

Figure 1.4 – How things will work after the migration process

Once everything is migrated, every page of the BO and FO will rely on the Symfony core and the full system will be able to use Doctrine entities. This process is likely to spend some years. The full PrestaShop open source project is working on it.