...
This is the main object in PrestaShop 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 as well. The class implements accessors for each attribute.
Defining the model
You must use the $definition
static variable in order to define the model.
...
Code Block |
---|
'multilang_shop' => true |
The main methods
Any overriding of its methods is bound to influence how all the other classes and methods act. Use with care.
Method name and parameters | Description |
---|
_ |
_ |
Return object validation rules (field validity).
getFields()
Prepare fields for ObjectModel class (add, update).
construct($id = NULL, $id_lang = NULL) | Build object. |
save($nullValues = false, $autodate = true)
add |
($autodate = true, $nullValues = false) | Save current object to database (add or update). |
update($nullValues = false)
associateTo(integer|array $id_shops) | Associate an item to its context. |
delete() | Delete current object from database. |
deleteImage(mixed $force_delete = false) | Delete images associated with the object. |
deleteSelection($selection) | Delete several objects from database. |
getFields() | Prepare fields for ObjectModel class (add, update). |
getValidationRules($className = _CLASS_) | Return object validation rules (field validity). |
save($nullValues = false, $autodate = true) | Save current object to database (add or update). |
toggleStatus() | Toggle object's status in database. |
update($nullValues = false) | Update current object to database. |
validateFields($die = true, $errorReturn = false) | Check for field validity before database interaction. |
The DBQuery class
The DBQuery class is a query builder, which helps you creation SQL queries. For instance:
Code Block |
---|
$sql = new DbQuery(); $sql->select('*'); $sql->from('cms', 'c'); $sql->innerJoin('cms_lang', 'l', 'c.id_cms = l.id_cms AND l.id_lang = '.(int)$id_lang); $sql->where('c.active = 1'); $sql->orderBy('position'); return Db::getInstance()->executeS($sql |
Here are some of the methods from this class:
Method name and parameters | Description |
---|---|
__toString() | Generate and get the query. |
string build() | Generate and get the query |
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 HAVING clause (each restriction will be separated by 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 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 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.
...
This method receives one (and only one) argument: an array of the contextual information sent to the hook.
Code Block |
---|
public function hookDisplayNameOfHook($params) { // Your code. } |
...