Child pages
  • Public and overloadable methods
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Table of content

Public and overloadable methods

With its overriding system, PrestaShop makes it possible to override many of its core functions. But overriding cannot be done if you do not know which method to replace. This list should help you.

You can learn more about overriding PrestaShop by reading the following articles:

If you do not want to replace a method, but simply add to it, remember to call the parent eponymous method somewhere in your method.

class Product extends ProductCore
{
	public function __construct($id_product = NULL, $full = false, $id_lang = NULL)
	{
		echo 'Hello World !';
		parent::__construct($id_product, $full, $id_lang);
	}
}

ObjectModelCore (ObjectModel.php)

This is the main object from PrestaShop's object model. Any overriding of its methods is bound to influence how all the other classes and methods act. Use carefully.

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 status in database.

validateFields($die = true, $errorReturn = false)

Check for fields validity before database interaction.

ToolsCore (Tools.php)

This class relates to the PrestaShop set of tools, found in the admin's Tools tab.

Method name and parameters

Description

passwdGen($length = 8)

Random password generator.

redirect($url, $baseUri = _PS_BASE_URI_)

Redirect user to another page.

redirectLink($url)

Redirect url wich allready PS_BASE_URI.

redirectAdmin($url)

Redirect user to another admin page.

getProtocol($use_ssl = null)

Return the set protocol according to configuration (https).

getHttpHost($http = false, $entities = false)

Return the <b>current</b> host used, with the protocol (http or https) if $http is true. This function should not be used to choose http or https domain name. Use Tools::getShopDomain() or Tools::getShopDomainSsl instead.

getShopDomain($http = false, $entities = false)

Returns domain name according to configuration and ignoring ssl.

getShopDomainSsl($http = false, $entities = false)

returns domain name according to configuration and depending on ssl activation.

getServerName()

Get the server variable SERVER_NAME.

getRemoteAddr()

Get the server variable REMOTE_ADDR, or the first ip of HTTP_X_FORWARDED_FOR (when using proxy).

usingSecureMode()

Check if the current page use SSL connection on not.

getCurrentUrlProtocolPrefix()

Get the current url prefix protocol (https/http).

secureReferrer($referrer)

Secure an URL referrer.

getValue($key, $defaultValue = false)

Get a value from $_POST / $_GET. If unavailable, take a default value.

setCookieLanguage()

Change language in cookie while clicking on a flag.

switchLanguage()

Set cookie id_lang.

setCurrency()

Set cookie currency from POST or default currency.

displayPrice($price, $currency = NULL, $no_utf8 = false)

Return price with currency sign for a given product.

convertPrice($price, $currency = NULL, $to_currency = true)

Return price converted.

dateFormat($params, &$smarty)

Display date regarding to language preferences.

displayDate($date, $id_lang, $full = false, $separator = '-')

Display date regarding to language preferences.

safeOutput($string, $html = false)

Sanitize a string.

deleteDirectory($dirname, $delete_self = true)

Delete directory and subdirectories.

displayError($string = 'Fatal error', $htmlentities = true)

Display an error according to an error code.

dieObject($object, $kill = true)

Display an error with detailed object.

isSubmit($submit)

Check if submit has been posted.

getMetaTags($id_lang, $page_name)

Get meta tages for a given page.

getHomeMetaTags($id_lang, $page_name)

Get meta tags for a given page.

encrypt($passwd)

Encrypt password.

getToken($page = true)

Get token to prevent CSRF.

getAdminToken($string)

Encrypt password.

getPath($id_category, $path = '', $linkOntheLastItem = false, $categoryType = 'products')

Get the user's journey.

link_rewrite($str, $utf8_decode = false)

Return the friendly url from the provided string.

str2url($str)

Return a friendly url made from the provided string. If the mbstring library is available, the output is the same as the js function of the same name.

truncate($str, $maxLen, $suffix = '...')

Truncate strings.

dateYears()

Generate date form.

dateDays()

 

dateMonths()

 

dateFrom($date)

 

dateTo($date)

 

toCamelCase($str, $capitaliseFirstChar = false)

Translates a string with underscores into camel case (e.g. first_name -> firstName).

addJS($js_uri)

Load a javascript file in the header.

addCSS($css_uri, $css_media_type = 'all')

Add a stylesheet at any time.

cccCss()

Combine Compress and Cache CSS (ccc) calls.

cccJS()

Combine Compress and Cache (ccc) JS calls.

jsonDecode($json, $assoc = false)

Convert json string to php array / object.

ZipTest($fromFile)

Try to open a zip file in order to check if it's valid.

ZipExtract($fromFile, $toDir)

Extract a zip file to the given directory.

getProductsOrder($type, $value = null)

Get products order field name for queries.

convertBytes($value)

Convert a shorthand byte value from a PHP configuration directive to an integer value.

AdminTabCore (AdminTab.php)

Method name and parameters

Description

l($string, $class = 'AdminTab', $addslashes = FALSE, $htmlentities = TRUE)

use translations files to replace english expression.

validateRules($className = false)

Manage page display (form, list...).

_childValidation()

Overload this method for custom checking in validateRules().

ajaxPreProcess()

a method called in ajax-tab.php before displayConf().

ajaxProcess()

the default handle method for request with ajax-tab.php.

postImage($id)

Overload this method for custom checking in postProcess()'s object creation/update routine.

copyFromPost(&$object, $table)

Copy datas from $_POST to object.

displayWarning($warn)

Display a warning message.

getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL)

Get the current objects' list form the database.

displayImage($id, $image, $size, $id_image = NULL, $token = NULL, $disableCache = false)

Display image aside object form.

displayListHeader($token = NULL)

Display list header (filtering, pagination and column names).

displayTop()

Overload this method for custom display in displayList().

displayFlags($languages, $defaultLanguage, $ids, $id, $return = false)

Display flags in forms for translations.

PDFCode (PDF.php)

Method name and parameters

Description

Header()

Invoice header.

Footer()

Invoice footer.

ConfigurationCore (Configuration.php)

Method name and parameters

Description

getTranslationsFieldsChild()

Check then return multilingual fields for database interaction.

deleteByName($key)

Delete a configuration key in database (with or without language management).

get($key, $id_lang = NULL)

Get a single configuration value (in one language only).

set($key, $values)

Set TEMPORARY a single configuration value (in one language only).

getInt($key)

Get a single configuration value (in multiple languages).

getMultiple($keys, $id_lang = NULL)

Get several configuration values (in one language only).

getMultipleInt($keys)

Get several configuration values (in multiple languages).

updateValue($key, $values, $html = false)

Update configuration key and value into database (automatically insert if key does not exist).

CookieCore (Cookie.php)

Method name and parameters

Description

setExpire($expire)

Set expiration date.

__get($key)

Magic method wich return cookie data from _content array.

__isset($key)

Magic method which check if key exists in the cookie.

__set($key, $value)

Magic method wich add data into _content array.

__unset($key)

Magic method wich delete data into _content array.

isLogged($withGuest = false)

Check customer informations saved into cookie and return customer validity.

isLoggedBack()

Check employee informations saved into cookie and return employee validity.

logout()

Delete cookie.

mylogout()

Soft logout, delete everything links to the customer but leave there affiliate's informations.

update($nullValues = false)

Get cookie content.

write()

Save cookie with setcookie().

getFamily($origin)

Get a family of variables (e.g. "filter_").

DbCore (Db.php)

Method name and parameters

Description

getInstance($master = 1)

Get Db object instance (Singleton).

autoExecute($table, $values, $type, $where = false, $limit = false, $use_cache = 1)

Filter SQL query within a blacklist.

autoExecuteWithNullValues($table, $values, $type, $where = false, $limit = false)

Filter SQL query within a blacklist.

pSQL($string, $htmlOK = false)

Sanitize data which will be injected into SQL query.

nl2br2($string)

Convert \n and \r\n and \r to <br />.

LinkCore (Link.php)

Method name and parameters

Description

getProductDeletePictureLink($product, $id_picture)

This function returns a link to delete a customization picture file.

getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL, $id_lang = NULL)

Return the correct link for product/category/supplier/manufacturer.

getCategoryLink($id_category, $alias = NULL, $id_lang = NULL)

 

getCMSCategoryLink($id_category, $alias = NULL, $id_lang = NULL)

 

getCMSLink($cms, $alias = null, $ssl = false, $id_lang = NULL)

 

getSupplierLink($id_supplier, $alias = NULL, $id_lang = NULL)

 

getManufacturerLink($id_manufacturer, $alias = NULL, $id_lang = NULL)

 

getCustomLink($id_custom, $page, $prefix = '~', $alias = NULL, $id_lang = NULL)

 

getImageLink($name, $ids, $type = NULL)

Returns a link to a product image for display. Note: the new image filesystem stores product images in subdirectories of img/p/.

getMediaLink($filepath)

 

preloadPageLinks()

 

getPageLink($filename, $ssl = false, $id_lang = NULL)

 

getCatImageLink($name, $id_category, $type = null)

 

getLanguageLink($id_lang)

Create link after language change, for the change language block.

goPage($url, $p)

 

getPaginationLink($type, $id_object, $nb = false, $sort = false, $pagination = false, $array = false)

 

addSortDetails($url, $orderby, $orderway)

 

getLangLink($id_lang = NULL)

 

MailCore (Mail.php)

Method name and parameters

Description

Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = PS_MAIL_DIR, $die = false)

 

sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)

 

l($string, $id_lang = null)

This method is used to get the translation for email Object. For an object is forbidden to use htmlentities, we have to return a sentence with accents.

FrontControllerCore (FrontController.php)

Method name and parameters

Description

preProcess()

Overload this method for custom display. This runs between the initialization of the page and the display of the header.

process()

Overload this method for custom display. This runs between the display of the header and the display of the content.

  • No labels