...
Code Block |
---|
/** * Example from the CMS model (CMSCore) */ public static $definition = array( 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), // Lang fields 'meta_description' => array('type' =>self> self::TYPE_STRING, 'lang' =>true> true, 'validate' => 'isGenericName', 'size' =>255> 255), 'meta_keywords' => array('type' =>self> self::TYPE_STRING, 'lang' =>true> true, 'validate' => 'isGenericName', 'size' =>255> 255), 'meta_title' => array('type' =>self> self::TYPE_STRING, 'lang' =>true> true, 'validate' => 'isGenericName', 'required' =>true> true, 'size' =>128> 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' =>true> true, 'validate' => 'isLinkRewrite', 'required' =>true> true, 'size' =>128> 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); |
...
Method name and parameters | Description |
---|---|
getValidationRules($className = _CLASS_) | Return object validation rules (fields validity). |
getFields() | Prepare fields for ObjectModel class (add, update). |
__construct($id = NULL, $id_lang = NULL) | Build object. |
save($nullValues = false, $autodate = true) | Save current object to database (add or update). |
add($autodate = true, $nullValues = false) | Save current object to database (add or update). |
add($autodate = true, $nullValues = false) | Add current object to database. |
update($nullValues = false) | Update current object to database. |
delete() | Delete current object from database. |
deleteSelection($selection) | Delete several objects from database. |
toggleStatus() | Toggle object's status in database. |
validateFields($die = true, $errorReturn = false) | Check for fields validity before database interaction. |
The DBQuery class
The DBQuery class is a query builder, which helps you creation SQL queries. For instance:
...
All of PrestaShop's controllers actually override the Controller
class through another inheriting class, such as AdminController
, ModuleAdminController
, FrontController
or ModuleFrontController
.
The FrontController class
...
__contruct()
: Sets all the controller's member variables.init()
: Initializes the controller.setMedia()
orsetMobileMedia()
: Adds all JavaScript and CSS specifics to the page so that they can be combined, compressed and cached (see PrestaShop's CCC tool, in the back-office "Performance" page, under the "Advanced preferences" menu).postProcess()
: HandlesajaxProcess
.initHeader()
: Called beforeinitContent()
.initContent()
: Initialize Initializes the content.initFooter()
: Called afterinitContent()
.display()
ordisplayAjax()
: Displays the content.
...
PrestaShop's controllers are all stored in the /controllers
folder, and use the "Core" suffix.
For instance, when working with the category controller:
...
In order to override a controller, you must first create a new class without the "Core" suffix, and place its file in the /override/controllers
folder.
...
Token | Description |
---|---|
date_add | The date and time the cookie was created (in YYYY-MM-DD HH:MM:SS format). |
id_lang | The ID of the selected language. |
id_currency | The ID of the selected currency. |
last_visited_category | The ID of the last visited category of product listings. |
ajax_blockcart_display | Whether the cart block is "expanded" or "collapsed". |
viewed | The IDs of recently viewed products as a comma-separated list. |
id_wishlist | The ID of the current wishlist displayed in the wishlist block. |
checkedTOS | Whether the "Terms of service" checkbox has been ticked (1 if it has and 0 if it hasn't) |
id_guest | The guest ID of the visitor when not logged in. |
id_connections | The connection ID of the visitor's current session. |
id_customer | The customer ID of the visitor when logged in. |
customer_lastname | The last name of the customer. |
customer_firstname | The first name of the customer. |
logged | Whether the customer is logged in. |
passwd | The MD5 hash of the _COOKIE_KEY_ in config/settings.inc.php and the password the customer used to log in. |
The email address that the customer used to log in. | |
id_cart | The ID of the current cart displayed in the cart block. |
checksum | The 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. |
...
Token | Description |
---|---|
date_add | The date and time the cookie was created (in YYYY-MM-DD HH:MM:SS format). |
id_lang | The ID of the selected language. |
id_employee | The ID of the employee. |
lastname | The last name of the employee. |
firstname | The first name of the employee. |
The email address the employee used to log in. | |
profile | The ID of the profile that determines which tabs the employee can access. |
passwd | The MD5 hash of the _COOKIE_KEY_ in config/settings.inc.php and the password the employee used to log in. |
checksum | The 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. |
...
Code Block |
---|
public function install()
{
return parent::install() && $this->registerHook('NameOfHook');
}
|
Existing hooks: front-office
...
Hook name | Description |
---|---|
displayHeader | Called between within the HEAD HTML <head> tags. Ideal location for adding JavaScript and CSS files. |
displayTop | Called in the page's header. |
displayLeftColumn | Called when loading the left column. |
displayRightColumn | Called when loading the right column. |
displayFooter | Called in the page's footer. |
displayHome | Called at the center of the homepage. |
...
Hook name | Description |
---|---|
displayLeftColumnProduct | Called right before the "Print" link, under the picture. |
displayRightColumnProduct | Called right after the block for the "Add to Cart" button. |
displayProductButtons | Called inside the block for the "Add to Cart" button, right after that button. |
actionProductOutOfStock | Called inside the block for the "Add to Cart" button, right after the "Availability" information. |
displayFooterProduct | Called right before the tabs. |
displayProductTab | Called in tabs list, such as "More info", "Data sheet", "Accessories", etc... |
displayProductTabContent | Called when a tab is clicked. |
...