Book Image

PrestaShop Module Development

By : Serny
Book Image

PrestaShop Module Development

By: Serny

Overview of this book

If you are a developer who is new to PrestaShop and wants to get a good foundation in development on the PrestaShop framework, this book is for you. It's assumed that you will have some experience with PHP5, jQuery, and HTML/CSS (no need to be an expert on it).
Table of Contents (13 chapters)
12
Index

Updating the module code


Updating the MySQL table is good, but, for the moment, our module does not use this new field.

Updating the ObjectModel class

Since we use an ObjectModel class to insert comments and retrieve it, we will add the id_shop field in this class.

In your classes/MyModComment.php file, add the shop ID just below the comment ID:

public $id_shop;

Then, add it in the fields list of the $definitions array:

'id_shop' => array('type' => self::TYPE_INT, 'validate' =>
'isUnsignedId', 'required' => true),

Note

If you don't remember how an ObjectModel class works, please refer to Chapter 5, Front Controllers, Object Models, and Overrides.

Now, open the controllers/hook/displayProductTabContent.php controller and search for the processProductTabContent method where you’re doing the comment’s insertion in the database with your ObjectModel class. You just have to set the id_shop field before calling the add method of your object:

$MyModComment->id_shop = (int)$this->context...