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

Executing a hook

As we explained before, we can use hooks to customize our shop and we can register modules to them to trigger our customized behavior. We know how to register, unregister, and define the custom behavior inside the module definition. To get the full scope, we now need to see how to execute a hook in the shop, making the module triggers possible.

Hooks can be executed anywhere in the code of PrestaShop, from legacy to Symfony controllers, and from Smarty to Twig themed templates.

Executing a hook from a legacy controller

Any legacy controller can use the static method named exec() from the Hook object. You can find its definition in the /classes/Hook.php file. We commonly use it as follows:

Hook::exec($hook_name, $params = array())

This includes $hook_name (the string name of the hook to execute) and $params (an array containing the necessary objects for good use of the hook).

For example, if you go to the /classes/controller/Controller.php legacy controller...