Child pages
  • Diving into PrestaShop Core development

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The ObjectModel class

This is the main object in of PrestaShop's object model. It can be overridden with precaution.

It is an Active Record kind of class (see: http://en.wikipedia.org/wiki/Active_record_pattern). PrestaShop's database table attributes or view attributes are encapsulated in the class. Therefore, the class is tied to a database record. After the object has been instantiated, a new record is added to the database. Each object retrieves its data from the database; when an object is updated, the record to which it is tied is update updated as well. The class implements accessors for each attribute.

...

In order to have an object which depend depends on the current store, and in many languages:

...

The main methods

Any overriding of its the ObjectModel methods is bound to influence how all the other classes and methods act. Use with care.

...

The DBQuery class is a query builder , which helps you creation create SQL queries. For instance:

...

Method name and parametersDescription
__toString()Generate and get the query.
string build()Generate and get the query (return a string).
from(string $table, mixed $alias = null)Set table for FROM clause.
groupBy(string $fields)Add a GROUP BY restriction.
having(string $restriction)

Add a restriction in the HAVING clause (each restriction will be separated by an AND statement).

innerJoin(string $table, string $alias = null, string $on = null)

Add INNER JOIN clause, E.g. $this->innerJoin('product p ON ...').

join(string $join)

Add JOIN clause, E.g. $this->join('RIGHT JOIN'._DB_PREFIX_.'product p ON ...');.

leftJoin(string $table, string $alias = null, string $on = null)Add LEFT JOIN clause.
leftOuterJoin(string $table, string $alias = null, string $on = null)

Add LEFT OUTER JOIN clause.

limit(string $limit, mixed $offset = 0)Limit results in query.
naturalJoin(string $table, string $alias = null)Add NATURAL JOIN clause.
orderBy(string $fields)Add an ORDER B restriction.
select(string $fields)Add fields in query selection.
where(string $restriction)

Add a restriction in WHERE clause (each restriction will be separated by an AND statement).

The Dispatcher

The Dispatcher is one of the main technical features of v1.5. It handles URL redirections. Instead of using multiple files on in the root folder like product.php, order.php or category.php, only one file is used: index.php. From now on, internal URL will look like index.php?controller=category, index.php?controller=product, etc.

...

Code Block
http://myprestashop.com/index.php?controller=category&id_category=3&id_lang=1
http://myprestashop.com/index.php?controller=product&id_product=1&id_lang=12

...and when URL-rewriting is on (or "Friendly URLs"), PrestaShop's Dispatcher will correctly support this URL form:

Code Block
http://myprestashop.com/en/3-music-ipods
http://myprestashop.com/enfr/1-ipod-nano.html

There are several advantages for this system:

...

In the MVC architecture, a controller Controller manages the synchronization events between the View and the Model, and keeps them up to date. It receives all the user events and triggers the actions to perform.
If an action needs data to be changed, the Controller will "ask" the Model to change the data, and in turn the Model will notify the View that the data has been changed, so that the View can update itself.

All of PrestaShop's controllers actually override the Controller class through another inheriting class, such as AdminController, ModuleAdminController, FrontController or , ModuleFrontController, etc.

The FrontController class

...

For instance, when working with the category Category controller:

  • File: /controllers/CategoryController.php
  • Class: CategoryControllerCore

...

For instance, when overriding the category Category controller:

  • File: /override/controllers/front/CategoryController.php
  • Class: CategoryController

...

Data stored in a visitor/client's cookie

 

TokenDescription
date_addThe date and time the cookie was created (in YYYY-MM-DD HH:MM:SS format).
id_langThe ID of the selected language.
id_currencyThe ID of the selected currency.
last_visited_categoryThe ID of the last visited category of product listings.
ajax_blockcart_displayWhether the cart block is "expanded" or "collapsed".
viewedThe IDs of recently viewed products as a comma-separated list.
id_wishlistThe ID of the current wishlist displayed in the wishlist block.
checkedTOSWhether the "Terms of service" checkbox has been ticked (1 if it has and 0 if it hasn't)
id_guestThe guest ID of the visitor when not logged in.
id_connectionsThe connection ID of the visitor's current session.
id_customerThe customer ID of the visitor when logged in.
customer_lastnameThe last name of the customer.
customer_firstnameThe first name of the customer.
loggedWhether the customer is logged in.
passwdThe MD5 hash of the _COOKIE_KEY_ in config/settings.inc.php and the password the customer used to log in.
emailThe email address that the customer used to log in.
id_cartThe ID of the current cart displayed in the cart block.
checksumThe Blowfish checksum used to determine whether the cookie has been modified by a third party.
The customer will be logged out and the cookie deleted if the checksum doesn't match.

Data stored in an employee/administrator's cookie

 

TokenDescription
date_addThe date and time the cookie was created (in YYYY-MM-DD HH:MM:SS format).
id_langThe ID of the selected language.
id_employeeThe ID of the employee.
lastnameThe last name of the employee.
firstnameThe first name of the employee.
emailThe email address the employee used to log in.
profileThe ID of the profile that determines which tabs the employee can access.
passwdThe MD5 hash of the _COOKIE_KEY_ in config/settings.inc.php and the password the employee used to log in.
checksumThe Blowfish checksum used to determine whether the cookie has been modified by a third party.
If the checksum doesn't match, the customer will be logged out and the cookie is deleted .
  

Hooks

Hooks are a way to associate your code to some specific PrestaShop events.

...

It is easy to call a hook from within a template file (.tpl): you simply have to use its name with the hook function. You can add the name of a module that you want the hook execute.

For instance:

Code Block
{hook h='displayLeftColumn' mod='blockcart'}

...

You can create new PrestaShop hooks by adding a new record in the ps_hook table in your MySQL database. You could do it the hard way:

Code Block
INSERT INTO `ps_hook` (`name`, `title`, `description`) VALUES ('nameOfHook', 'The name of your hook', 'This is a custom hook!');

Yes, you can do it like that...... but you need to know that, with PrestaShop 1.5, you don't need PrestaShop enables you to do it .Now, when your module executes the install method and you want to register a hook, you do it like thatthe easy way:

Code Block
$this->registerHook('NameOfHook');

...