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

Creating a database table on module installation

First of all, we will create a directory named install in the module directory. In this directory, create one file named install.sql in which you will put the SQL request that you want to execute on installation. In our case, it will be the mymod_comment table creation (the one we created manually in Chapter 2, Hooks):

CREATE TABLE IF NOT EXISTS `PREFIX_mymod_comment` (
  `id_mymod_comment` int(11) NOT NULL AUTO_INCREMENT,
  `id_product` int(11) NOT NULL,
  `grade` tinyint(1) NOT NULL,
  `comment` text NOT NULL,
  `date_add` datetime NOT NULL,
  PRIMARY KEY (`id_mymod_comment`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Note

As you can see, I replaced the usual ps_ with PREFIX_. That way, we will be able to replace the PREFIX_ string with the prefix chosen by the merchant. It's the method used in PrestaShop installer.

Then, in the install method in mymodcomments.php, we will load the SQL file content and execute it.

We might...