Book Image

PrestaShop Module Development

By : Fabien Serny
Book Image

PrestaShop Module Development

By: Fabien Serny

Overview of this book

Table of Contents (19 chapters)
PrestaShop Module Development
About the Author
About the Reviewers

Cleaning your code using the hook's controller

At this point, your main class, mymodcomments, should be of almost 300 lines. The following section is not a PrestaShop best practice; beware! During the next chapter, I'll use the module with hook controllers.

This is how I chose to split my code to have hook actions in a separate class. You can choose to do it differently (or not at all, in which case, you can skip this section).


I have attached two versions of the module with this chapter:

  • mymodcomments: This is the module you should have now

  • mymodcomments_with_hook_controllers: This is what the module should look like once you add the hook controllers

We will create one controller for each part of our module. For example, in the case of the displayProductTabContent hook, we have coded three methods:

  • processProductTabContent: This method inserts a comment in the database

  • assignProductTabContent: This method assigns data to Smarty

  • hookDisplayProductTabContent: This method calls the two previous...