Reader small image

You're reading from  PrestaShop Module Development

Product typeBook
Published inNov 2014
Reading LevelBeginner
Publisher
ISBN-139781783280254
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Fabien Serny
Fabien Serny
author image
Fabien Serny

Fabien Serny is a former core developer at PrestaShop. He has 10 years of experience in web development and e-commerce. He has worked for several big e-commerce companies in France, and then created his own company named 23Prod in late 2010. In 2014, along with two other former core developers from PrestaShop, he launched Froggy Commerce, a platform that sells simple and powerful modules for PrestaShop based on the needs of e-tailers. You can visit his websites http://www.23prod.com and http://www.froggy-commerce.com.
Read more about Fabien Serny

Right arrow

Using the database class to save comments


We will now register the comment and grade filled in by the visitor in the database. First, we will create a table in our database:

CREATE TABLE IF NOT EXISTS ps_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 ;

As you can see, the table contains five fields: the line identifier (in auto-increment), the product identifier, the grade, the comment, and the date of the comment.

Note

In PrestaShop, the naming conventions for the database field are:

  • Name your identifier field with the id_ prefix followed by the name of the table without the ps_ prefix

  • Name your date with the date_ prefix, such as date_comment

Create your table with your SQL admin tool (mine is phpMyAdmin; yeah, I know, I'm a bit old school). Beware! If you chose a different prefix than ps_...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
PrestaShop Module Development
Published in: Nov 2014Publisher: ISBN-13: 9781783280254

Author (1)

author image
Fabien Serny

Fabien Serny is a former core developer at PrestaShop. He has 10 years of experience in web development and e-commerce. He has worked for several big e-commerce companies in France, and then created his own company named 23Prod in late 2010. In 2014, along with two other former core developers from PrestaShop, he launched Froggy Commerce, a platform that sells simple and powerful modules for PrestaShop based on the needs of e-tailers. You can visit his websites http://www.23prod.com and http://www.froggy-commerce.com.
Read more about Fabien Serny