Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PrestaShop Module Development

You're reading from   PrestaShop Module Development Develop and customize powerful modules for PrestaShop 1.5 and 1.6

Arrow left icon
Product type Paperback
Published in Nov 2014
Publisher
ISBN-13 9781783280254
Length 254 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Fabien Serny Fabien Serny
Author Profile Icon Fabien Serny
Fabien Serny
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Creating a New Module FREE CHAPTER 2. Hooks 3. Using Context and its Methods 4. Building Module Updates 5. Front Controllers, Object Models, and Overrides 6. Admin Controllers and Hooks 7. The Carrier Module 8. The Payment Module 9. Multistore 10. Security and Performance A. Native Hooks Index

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image