Skip to content

Instantly share code, notes, and snippets.

@rseon
Last active December 28, 2023 18:27
Show Gist options
  • Select an option

  • Save rseon/3e582e55874721ebd1743958b1f11112 to your computer and use it in GitHub Desktop.

Select an option

Save rseon/3e582e55874721ebd1743958b1f11112 to your computer and use it in GitHub Desktop.
Prestashop cheatsheet (>= 1.5)

Prestashop 1.7 cheatsheet

The most common. For me. Mostly from comments in source code.

Updated with 1.7 code.

Address

/**
 * Specify if an address is already in base.
 *
 * @param int $id_address Address id
 * @return bool The address exists
 */
Address::addressExists(int $id_address) : bool

/**
 * Request to check if DNI field is required depending on the current selected country.
 *
 * @param int $idCountry
 * @return bool
 */
Address::dniRequired(int $idCountry) : bool

/**
 * Get Country and State of this Address.
 *
 * @param int $id_address Address ID
 * @return array
 */
Address::getCountryAndState(int $id_address) : array

/**
 * Get the first address id of the customer.
 *
 * @param int $id_customer Customer id
 * @param bool $active Active addresses only
 * @return bool|int|null
 */
Address::getFirstCustomerAddressId(int $id_customer, bool $active = true) : bool|int|null

/**
 * Get Zone ID for a given address.
 *
 * @param int $id_address Address ID for which we want to get the Zone ID
 * @return int Zone ID
 */
Address::getZoneById(int $id_address) : int

/**
 * Check if the Country is active for a given address.
 *
 * @param int $id_address Address ID for which we want to get the Country status
 * @return int Country status
 */
Address::isCountryActiveById(int $id_address) : bool

/**
 * Check if Address is used (at least one order placed).
 *
 * @return int Order count for this Address
 */
$Address->isUsed() : int|false

/**
 * Check if the address is valid.
 *
 * @param int $id_address Address id
 * @return bool The address is valid
 */
Address::isValid(int $id_address) : bool

Attachment

/**
 * Associate $id_product to the current object.
 *
 * @param int $idProduct id of the product to associate
 * @return bool true if success
 */
$Attachment->attachProduct(int $idProduct) : bool

/**
 * Associate an array of id_attachment $array to the product $id_product
 * and remove eventual previous association.
 *
 * @param int $idProduct Product ID
 * @param array $array Attachment IDs
 *
 * @return bool Whether the attachments have been successfully associated with the Product
 */
Attachment::attachToProduct(int $idProduct, array $array) : bool

/**
 * Delete Product attachments for the given Product ID.
 *
 * @param int $idProduct Product ID
 * @return bool
 */
Attachment::deleteProductAttachments(int $idProduct) : bool

/**
 * Get attachments.
 *
 * @param int $idLang Language ID
 * @param int $idProduct Product ID
 * @param bool $include Whether the attachments are included or excluded from the Product ID
 * @return array|false|mysqli_result|PDOStatement|resource|null Database query result
 */
Attachment::getAttachments(int $idLang, int $idProduct, bool $include = true) : array|false|mysqli_result|PDOStatement|resource|null

Attributes

/**
 * Get quantity for a given attribute combination
 * Check if quantity is enough to serve the customer.
 *
 * @param int $idProductAttribute Product attribute combination id
 * @param int $qty Quantity needed
 * @param Shop $shop Shop
 * @return bool Quantity is available or not
 */
Attribute::checkAttributeQty(int $idProductAttribute, int $qty, ?Shop $shop = null) : bool

/**
 * Reorder the attribute position within the Attribute group.
 * Call this method after deleting an attribute from a group.
 *
 * @param int $idAttributeGroup Attribute group ID
 * @param bool $useLastAttribute
 * @return bool Whether the result was successfully updated
 */
$Attribute->cleanPositions(int $idAttributeGroup, bool $useLastAttribute = true) : bool

/**
 * Get minimal quantity for product with attributes quantity.
 *
 * @param int $idProductAttribute Product Attribute ID
 * @return mixed Minimal quantity or false if no result
 */
Attribute::getAttributeMinimalQty(int $idProductAttribute) : int|false

/**
 * Get all attributes for a given language.
 *
 * @param int $idLang Language ID
 * @param bool $notNull Get only not null fields if true
 * @return array Attributes
 */
Attribute::getAttributes(int $idLang, bool $notNull = false) : array

/**
 * Get the highest attribute position from a group attribute
 *
 * @param int $idAttributeGroup AttributeGroup ID
 * @return int $position Position
 */
Attribute::getHigherPosition(int $idAttributeGroup) : int

/**
 * Check if the given name is an Attribute within the given AttributeGroup.
 *
 * @param int $idAttributeGroup AttributeGroup
 * @param string $name Attribute name
 * @param int $idLang Language ID
 * @return array|bool
 */
Attribute::isAttribute(int $idAttributeGroup, string $name, int $idLang) : array|bool

/**
 * Return true if the Attribute is a color.
 *
 * @return bool Color is the attribute type
 */
$Attribute->isColorAttribute() : bool

/**
 * Move an attribute inside its group.
 *
 * @param bool $direction Up (1) or Down (0)
 * @param int $position Current position of the attribute
 * @return bool Update result
 */
$Attribute->updatePosition(bool $direction, int $position) : bool

AttributeGroup

/**
 * Clean dead combinations
 * A combination is considered dead when its Attribute ID cannot be found.
 *
 * @return bool Whether the dead combinations have been successfully deleted
 */
AttributeGroup::cleanDeadCombinations() : bool

/**
 * Reorder group attribute position
 * Call it after deleting a group attribute.
 *
 * @return bool $return
 */
AttributeGroup::cleanPositions() : bool

/**
 * Get all attributes for a given language / group.
 *
 * @param int $idLang Language ID
 * @param int $idAttributeGroup AttributeGroup ID
 * @return array Attributes
 */
AttributeGroup::getAttributes(int $idLang, int $idAttributeGroup) : array

/**
 * Get all attributes groups for a given language.
 *
 * @param int $idLang Language id
 * @return array Attributes groups
 */
AttributeGroup::getAttributesGroups(int $idLang) : array

/**
 * Get the highest AttributeGroup position.
 *
 * @return int $position Position
 */
AttributeGroup::getHigherPosition() : int

/**
 * Move a group attribute.
 *
 * @param bool $direction Up (1) or Down (0)
 * @param int $position
 * @return bool Update result
 */
$AttributeGroup->updatePosition(bool $direction, int $position) : bool

Carrier

/**
 * Get delivery price for a given order.
 *
 * @param int $id_carrier Carrier ID
 * @param float $order_total Order total to pay
 * @param int $id_zone Zone id (for customer delivery address)
 * @param int|null $id_currency Currency ID
 * @return float Delivery price
 */
Carrier::checkDeliveryPriceByPrice(int $id_carrier, float $order_total, int $id_zone, ?int $id_currency = null) : float

/**
 * Get delivery price by total weight.
 *
 * @param int $id_carrier Carrier ID
 * @param float $total_weight Total weight
 * @param int $id_zone Zone ID
 *
 * @return float|bool Delivery price, false if not possible
 */
Carrier::checkDeliveryPriceByWeight(int $id_carrier, float $total_weight, int $id_zone) : float|bool

/**
 * Reorder Carrier positions
 * Called after deleting a Carrier.
 *
 * @return bool $return
 */
Carrier::cleanPositions() : bool

/**
 * Copy old carrier informations when update carrier.
 *
 * @param int $oldId Old id carrier (copy from that id)
 */
$Carrier->copyCarrierData(int $old_id) : void

/**
 * For a given {product, warehouse}, gets the carrier available.
 *
 * @since 1.5.0
 *
 * @param Product $product The id of the product, or an array with at least the package size and weight
 * @param int $id_warehouse Warehouse ID
 * @param int $id_address_delivery Delivery Address ID
 * @param int $id_shop Shop ID
 * @param Cart $cart Cart object
 * @param array &$error contain an error message if an error occurs
 * @return array Available Carriers
 */
Carrier::getAvailableCarrierList(Product $product, int $id_warehouse, ?int $id_address_delivery = null, ?int $id_shop = null, ?Cart $cart = null, array &$error = []) : array

/**
 * Get all carriers in a given language.
 *
 * @param int $id_lang Language id
 * @param int $modules_filters Possible values:
 *                             - PS_CARRIERS_ONLY
 *                             - CARRIERS_MODULE
 *                             - CARRIERS_MODULE_NEED_RANGE
 *                             - PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE
 *                             - ALL_CARRIERS
 * @param bool $active Returns only active carriers when true
 * @return array Carriers
 */
Carrier::getCarriers(int $id_lang, bool $active = false, bool $delete = false, int|false $id_zone = false, ?array $ids_group = null, int $modules_filters = self::PS_CARRIERS_ONLY) : array

/**
 * Get available Carriers for Order.
 *
 * @param int $id_zone Zone ID
 * @param array $groups Group of the Customer
 * @param Cart|null $cart Optional Cart object
 * @param array &$error Contains an error message if an error occurs
 * @return array Carriers for the order
 */
Carrier::getCarriersForOrder(int $id_zone, ?array $groups = null, ?int $cart = null, array &$error = []) : array

/**
 * Get the countries to which can be delivered.
 *
 * @param int $id_lang Language ID
 * @param bool $active_countries Only return active countries when true
 * @param bool $active_carriers Only return active carriers when true
 * @param null $contain_states Only return countries with states
 * @return array Countries to which can be delivered
 */
Carrier::getDeliveredCountries(int $id_lang, bool $active_countries = false, bool $active_carriers = false, ?int $contain_states = null) : array

/**
 * Get delivery price for a given order by total order price MINUS shipping costs.
 *
 * @param float $order_total Order total to pay
 * @param int $id_zone Zone id (for customer delivery address)
 * @param int|null $id_currency Currency ID
 * @return float Maximum delivery price
 */
$Carrier->getDeliveryPriceByPrice(float $order_total, int $id_zone, ?int $id_currency = null) : float

/**
 * Get delivery price for a given order.
 *
 * @param float $total_weight Total order weight
 * @param int $id_zone Zone ID (for customer delivery address)
 * @return float|bool Delivery price, false if not possible
 */
$Carrier->getDeliveryPriceByWeight(float $total_weight, int $id_zone) : float|bool

/**
 * Gets the highest carrier position.
 *
 * @return int $position
 */
Carrier::getHigherPosition() : int

/**
 * Get maximum delivery price by order total MINUS shipping costs.
 *
 * @param int $id_zone Zone ID
 * @return float Maximum delivery price
 */
$Carrier->getMaxDeliveryPriceByPrice(int $id_zone) : float

/**
 * Get maximum delivery price when range weight is used.
 *
 * @param int $id_zone Zone ID
 * @return false|string|null Maximum delivery price
 */
$Carrier->getMaxDeliveryPriceByWeight(int $id_zone) : false|string|null

/**
 * Check if Carrier is used (at least one order placed).
 *
 * @return int Order count for this carrier
 */
$Carrier->isUsed() : int

/**
 * Moves a carrier.
 *
 * @param bool $way Up (1) or Down (0)
 * @param int $position Current position of the Carrier
 * @return bool Whether the update was successful
 */
$Carrier->updatePosition(bool $way, int $position) : bool

Combination

/**
 * For a given product_attribute reference, returns the corresponding id.
 *
 * @param int $idProduct
 * @param string $reference
 * @return int id
 */
Combination::getIdByReference(int $idProduct, string $reference) : id

Configuration

/**
 * Delete a configuration key in database (with or without language management).
 *
 * @param string $key Key to delete
 * @return bool Deletion result
 */
Configuration::deleteByName(string $key) : bool

/**
 * Get a single configuration value (in one language only).
 *
 * @param string $key Key wanted
 * @param int $idLang Language ID
 * @return string Value
 */
Configuration::get(string $key, ?int $idLang = null, ?int $idShopGroup = null, ?int $idShop = null, ?string $default = false) : string

/**
 * Get several configuration values (in one language only).
 *
 * @param array $keys Keys wanted
 * @param int $idLang Language ID
 * @param int $idShopGroup
 * @param int $idShop
 * @return array Values
 */
Configuration::getMultiple(array $keys, ?int $idLang = null, ?int $idShopGroup = null, ?int $idShop = null) : array

/**
 * Check if key exists in configuration.
 *
 * @param string $key
 * @param int $idLang
 * @param int $idShopGroup
 * @param int $idShop
 * @return bool
 */
Configuration::hasKey(string $key, ?int $idLang = null, ?int $idShopGroup = null, ?int $idShop = null) : bool

/**
 * Set TEMPORARY a single configuration value (in one language only).
 *
 * @param string $key Configuration key
 * @param mixed $values `$values` is an array if the configuration is multilingual, a single string else
 * @param int $idShopGroup
 * @param int $idShop
 */
Configuration::set(string $key, mixed $values, ?int $idShopGroup = null, ?int $idShop = null) : void

/**
 * Update configuration key and value into database (automatically insert if key does not exist).
 * Values are inserted/updated directly using SQL, because using (Configuration) ObjectModel
 * may not insert values correctly (for example, HTML is escaped, when it should not be).
 *
 * @param string $key Configuration key
 * @param mixed $values $values is an array if the configuration is multilingual, a single string else
 * @param bool $html Specify if html is authorized in value
 * @param int $idShopGroup
 * @param int $idShop
 * @return bool Update result
 */
Configuration::updateValue(string $key, mixed $values, bool $html = false, ?int $idShopGroup = null, ?int $idShop = null) : bool

Customer

Retrieve logged user : $this->context->cookie->id_customer

/**
 * Check if e-mail is already registered in database.
 *
 * @param string $email e-mail
 * @param bool $returnId
 * @param bool $ignoreGuest To exclude guest customer
 * @return bool|int Customer ID if found
 *                  `false` otherwise
 */
Customer::customerExists(string $email, bool $returnId = false, bool $ignoreGuest = true) : int|false

/**
 * Return customer instance from its e-mail (optionally check password).
 *
 * @param string $email e-mail
 * @param string $plaintextPassword Password is also checked if specified
 * @param bool $ignoreGuest
 * @return bool|Customer|CustomerCore Customer instance
 */
$Customer->getByEmail(string $email, ?string $plaintextPassword = null, bool $ignoreGuest = true) : bool|Customer

/**
 * Return customers list.
 *
 * @param bool|null $onlyActive Returns only active customers when `true`
 * @return array Customers
 */
Customer::getCustomers(bool $onlyActive = null) : array

/**
 * Retrieve customers by email address.
 *
 * @param string $email
 * @return array
 */
Customer::getCustomersByEmail(string $email) : array

/**
 * Check id the customer is active or not.
 *
 * @param int $idCustomer
 * @return bool Customer validity
 */
Customer::isBanned(int $idCustomer) : bool

Database

/**
 * Executes a DELETE query.
 *
 * @param string $table Name of the table to delete
 * @param string $where WHERE clause on query
 * @param int $limit Number max of rows to delete
 * @param bool $use_cache Use cache or not
 * @param bool $add_prefix Add or not _DB_PREFIX_ before table name
 * @return bool
 */
Db::getInstance()->delete(string $table, string $where = '', int $limit = 0, bool $use_cache = true, bool $add_prefix = true) : bool

/**
 * Sanitize data which will be injected into SQL query.
 *
 * @param string $string SQL data which will be injected into SQL query
 * @param bool $html_ok Does data contain HTML code ? (optional)
 * @return string Sanitized data
 * 
 * Note : you can use the helper pSQL(string $string, bool $htmlOK = false)
 */
Db::getInstance()->escape(string $string, bool $html_ok = false, bool $bq_sql = false) : string

/**
 * Executes a query.
 *
 * @param string|DbQuery $sql
 * @param bool $use_cache
 * @return bool
 */
Db::getInstance()->execute(string|DbQuery $sql, bool $use_cache = true) : bool

/**
 * Executes return the result of $sql as array.
 *
 * @param string|DbQuery $sql Query to execute
 * @param bool $array Return an array instead of a result object (deprecated since 1.5.0.1, use query method instead)
 * @param bool $use_cache
 * @return array|false|mysqli_result|PDOStatement|resource|null
 * @throws PrestaShopDatabaseException
 */
Db::getInstance()->executeS(string|DbQuery $sql, bool $array = true, bool $use_cache = true) : array|false|mysqli_result|PDOStatement|resource|null

/**
 * Returns an associative array containing the first row of the query
 * This function automatically adds "LIMIT 1" to the query.
 *
 * @param string|DbQuery $sql the select query (without "LIMIT 1")
 * @param bool $use_cache Find it in cache first
 * @return array|bool|object|null
 */
Db::getInstance()->getRow(string|DbQuery $sql, bool $use_cache = true) : array|bool|object|null

/**
 * Returns a value from the first row, first column of a SELECT query.
 *
 * @param string|DbQuery $sql
 * @param bool $use_cache
 *
 * @return string|false|null
 */
Db::getInstance()->getValue(string|DbQuery $sql, bool $use_cache = true) : string|false|null

/**
 * Executes an INSERT query.
 *
 * @param string $table Table name without prefix
 * @param array $data Data to insert as associative array. If $data is a list of arrays, multiple insert will be done
 * @param bool $null_values If we want to use NULL values instead of empty quotes
 * @param bool $use_cache
 * @param int $type Must be Db::INSERT or Db::INSERT_IGNORE or Db::REPLACE
 * @param bool $add_prefix Add or not _DB_PREFIX_ before table name
 * @return bool
 * @throws PrestaShopDatabaseException
 */
Db::getInstance()->insert(string $table, array $data, bool $null_values = false, bool $use_cache = true, int $type = Db::INSERT, bool $add_prefix = true) : bool

/**
 * Get the ID generated from the previous INSERT operation.
 *
 * @return int|string
 */
Db::getInstance()->Insert_ID() : int|string

/**
 * Get number of rows for last result.
 *
 * @return int
 */
Db::getInstance()->numRows() : int

/**
 * Executes an UPDATE query.
 *
 * @param string $table Table name without prefix
 * @param array $data Data to insert as associative array. If $data is a list of arrays, multiple insert will be done
 * @param string $where WHERE condition
 * @param int $limit
 * @param bool $null_values If we want to use NULL values instead of empty quotes
 * @param bool $use_cache
 * @param bool $add_prefix Add or not _DB_PREFIX_ before table name
 * @return bool
 */
Db::getInstance()->update(string $table, array $data, string $where = '', int $limit = 0, bool $null_values = false, bool $use_cache = true, bool $add_prefix = true) : bool

Group

/**
 * Returns the list of groups
 * 
 * @param int $id_lang
 * @param int|false $id_shop
 * @return array
 */
Group::getGroups(int $id_lang, int|false $id_shop = false) : array

Image

/**
 * Return highest position of images for a product.
 *
 * @param int $idProduct Product ID
 *
 * @return int highest position of images
 */
Image::getHighestPosition(int $idProduct) : int

/**
 * Return available images for a product.
 *
 * @param int $idLang Language ID
 * @param int $idProduct Product ID
 * @param int $idProductAttribute Product Attribute ID
 * @param int $idShop Shop ID
 *
 * @return array Images
 */
Image::getImages(int $idLang, int $idProduct, ?int $idProductAttribute = null, ?int $idShop = null) : array

/**
 * Return number of images for a product.
 *
 * @param int $idProduct Product ID
 *
 * @return int number of images
 */
Image::getImagesTotal(int $idProduct) : int

/**
 * Check if a product has an image available.
 *
 * @param int $idLang Language ID
 * @param int $idProduct Product ID
 * @param int $idProductAttribute Product Attribute ID
 *
 * @return bool
 */
Image::hasImages(int $idLang, int $idProduct, ?int $idProductAttribute = null) : bool

Language

/**
 * Return iso code from id (installed languages only).
 *
 * @param int $id_lang Language ID
 * @return string 2-letter ISO code
 */
Language::getIsoById(int $id_lang) : string

/**
 * Returns installed languages.
 *
 * @param bool $active Select only active languages
 * @param int|false $id_shop Shop ID
 * @param bool $ids_only If true, returns an array of language IDs
 * @return array[] Language information
 */
Language::getLanguages(bool $active = true, int|false $id_shop = false, bool $ids_only = false) : array

Link

Retrieve global from PHP : $this->context->link and from Smarty : {$link}

/**
 * Use controller name to create a link.
 *
 * @param string $controller
 * @param bool $withToken include or not the token in the url
 * @param array(string) $sfRouteParams Optional parameters to use into New architecture specific cases. If these specific cases should redirect to legacy URLs, then this parameter is used to complete GET query string
 * @param array $params Optional
 * @return string url
 */
$Link->getAdminLink(string $controller, bool $withToken = true, array $sfRouteParams = [], array $params = []) : string

/**
 * Create a link to a category.
 *
 * @param mixed $category Category object (can be an ID category, but deprecated)
 * @param string $alias
 * @param int $idLang
 * @param string $selectedFilters Url parameter to autocheck filters of the module blocklayered
 * @return string
 */
$Link->getCategoryLink(Category|int $category, ?string $alias = null, ?int $idLang = null, ?string $selectedFilters = null, ?int $idShop = null, bool $relativeProtocol = false) : string

/**
 * Create a link to a CMS category.
 *
 * @param mixed $cmsCategory CMSCategory object (can be an ID category, but deprecated)
 * @param string $alias
 * @param int $idLang
 * @param null $idShop
 * @param bool $relativeProtocol
 * @return string
 */
$Link->getCMSCategoryLink(CMSCategory|int $cmsCategory, ?string $alias = null, ?int $idLang = null, ?int $idShop = null, bool $relativeProtocol = false) : string

/**
 * Create a link to a CMS page.
 *
 * @param CMS|int $cms CMS object
 * @param string $alias
 * @param bool $ssl
 * @param int $idLang
 * @return string
 */
$Link->getCMSLink(CMS|int $cms, ?string $alias = null, ?bool $ssl = null, ?int $idLang = null, ?int $idShop = null, bool $relativeProtocol = false) : string

/**
 * Returns a link to a product image for display
 * Note: the new image filesystem stores product images in subdirectories of img/p/.
 * 
 * @param string $name rewrite link of the image
 * @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new)
 * @param string $type
 * @return string
 */
$Link->getImageLink(string $name, string $ids, ?string $type = null) : string

/**
 * Returns a link to a manufacturer image for display.
 * 
 * @param $idManufacturer
 * @param null $type image type (small_default, medium_default, large_default, etc.)
 * @return string
 */
$Link->getManufacturerImageLink(int $idManufacturer, ?string $type = null) : string

/**
 * Create a link to a manufacturer.
 *
 * @param mixed $manufacturer Manufacturer object (can be an ID supplier, but deprecated)
 * @param string $alias
 * @param int $idLang
 * @param null $idShop
 * @param bool $relativeProtocol
 * @return string
 */
$Link->getManufacturerLink(Manufacturer|int $manufacturer, ?string $alias = null, ?int $idLang = null, ?int $idShop = null, bool $relativeProtocol = false) : string

/**
 * Create a link to a module.
 *
 * @param string $module Module name
 * @param string $controller
 * @param array $params
 * @param bool|null $ssl
 * @param int $idLang
 * @param null $idShop
 * @param bool $relativeProtocol
 * @return string
 */
$Link->getModuleLink(string $module, string $controller = 'default', array $params = [], ?bool $ssl = null, ?int $idLang = null, ?int $idShop = null, bool $relativeProtocol = false) : string

/**
 * Create a simple link.
 *
 * @param string $controller
 * @param bool $ssl
 * @param int $idLang
 * @param string|array $request
 * @param bool $requestUrlEncode Use URL encode
 * @return string Page link
 */
$Link->getPageLink(string $controller, ?bool $ssl = null, ?int $idLang = null, ?string|array $request = null, bool $requestUrlEncode = false, ?int $idShop = null, bool $relativeProtocol = false) : string

/**
 * Create a link to a product.
 *
 * @param mixed $product Product object (can be an ID product, but deprecated)
 * @param string $alias
 * @param string $category
 * @param string $ean13
 * @param int $idLang
 * @param int $idShop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart
 * @param int $ipa ID product attribute
 * @return string
 */
$Link->getProductLink(Product|int $product, ?string $alias = null, ?string $category = null, ?string $ean13 = null, ?int $idLang = null, ?int $idShop = null, ?int $ipa = null, bool $force_routes = false, bool $relativeProtocol = false, bool $addAnchor = false, array $extraParams = []) : string

/**
 * Returns a link to a supplier image for display.
 * 
 * @param $idSupplier
 * @param null $type image type (small_default, medium_default, large_default, etc.)
 * @return string
 */
$Link->getSupplierImageLink(int $idSupplier, ?string $type = null) : string

/**
 * Create a link to a supplier.
 *
 * @param mixed $supplier Supplier object (can be an ID supplier, but deprecated)
 * @param string $alias
 * @param int $idLang
 * @return string
 */
$Link->getSupplierLink(Supplier|int $supplier, ?string $alias = null, ?int $idLang = null, ?int $idShop = null, bool $relativeProtocol = false) : string

Module

/**
 * Return an instance of the specified module.
 *
 * @param string $module_name Module name
 *
 * @return Module|false
 */
Module::getInstanceByName(string $module_name) : Module|false

/**
 * Connect module to a hook.
 *
 * @param string|array $hook_name Hook name
 * @param array|null $shop_list List of shop linked to the hook (if null, link hook to all shops)
 *
 * @return bool result
 */
$Module->registerHook(string $hook_name, ?array $shop_list = null) : bool

/**
 * Unregister module from hook.
 *
 * @param int|string $hook_id Hook id (can be a hook name since 1.5.0)
 * @param array|null $shop_list List of shop
 *
 * @return bool result
 */
$Module->unregisterHook(int|string $hook_id, ?array $shop_list = null) : bool

ObjectModel

All Prestashop classes inherits of ObjectModel class so then can call these methods (Product, Combination, Shop... all classes in /classes)

/**
 * Adds current object to the database.
 *
 * @param bool $auto_date
 * @param bool $null_values
 * @return bool Insertion result
 */
$ObjectModel->add(bool $auto_date = true, bool $null_values = false) : bool

/**
 * This function associate an item to its context.
 *
 * @param int|array $id_shops
 * @return bool|void
 */
$ObjectModel->associateTo(array|int $id_shops) : bool|void

/**
 * Clears cache entries that have this object's ID.
 *
 * @param bool $all If true, clears cache for all objects
 */
$ObjectModel->clearCache(bool $all = false) : void

/**
 * Deletes current object from database.
 *
 * @return bool True if delete was successful
 */
$ObjectModel->delete() : bool

/**
 * Delete images associated with the object.
 *
 * @param bool $force_delete
 * @return bool
 */
$ObjectModel->deleteImage(bool $force_delete = false) : bool

/**
 * Deletes multiple objects from the database at once.
 *
 * @param array $ids array of objects IDs
 * @return bool
 */
$ObjectModel->deleteSelection(array $ids) : bool

/**
 * Takes current object ID, gets its values from database,
 * saves them in a new row and loads newly saved values as a new object.
 *
 * @return ObjectModel|false
 */
$ObjectModel->duplicateObject() : ObjectModel|false

/**
 * Copies shop association data from object with specified ID.
 *
 * @param $id
 * @return bool|void
 */
$ObjectModel->duplicateShops(int $id) : bool|void

/**
 * Gets the list of associated shop IDs.
 *
 * @return array
 */
$ObjectModel->getAssociatedShops() : array

/**
 * Checks if current object is associated to a shop.
 *
 * @param int|null $id_shop
 * @return bool
 */
$ObjectModel->isAssociatedToShop(?int $id_shop = null) : bool

/**
 * Saves current object to database (add or update).
 *
 * @param bool $null_values
 * @param bool $auto_date
 * @return bool Insertion result
 */
$ObjectModel->save(bool $null_values = false, bool $auto_date = true) : bool

/**
 * Does a soft delete on current object, using the "deleted" field in DB
 * If the model object has no "deleted" property or no "deleted" definition field it will throw an exception
 *
 * @return bool
 */
$ObjectModel->softDelete() : bool

/**
 * Toggles object status in database.
 * If the model object has no "active" property or no "active" definition field it will throw an exception
 *
 * @return bool Update result
 */
$ObjectModel->toggleStatus() : bool

/**
 * Updates the current object in the database.
 *
 * @param bool $null_values
 * @return bool
 */
$ObjectModel->update(bool $null_values = false) : bool

/**
 * Validate a single field.
 *
 * @since 1.5.0.1
 *
 * @param string $field Field name
 * @param mixed $value Field value
 * @param int|null $id_lang Language ID
 * @param array $skip array of fields to skip
 * @param bool $human_errors if true, uses more descriptive, translatable error strings
 * @return true|string true or error message string
 */
$ObjectModel->validateField(string $field, mixed $value, ?int $id_lang = null, array $skip = [], bool $human_errors = false) : bool|string

/**
 * Checks if object field values are valid before database interaction.
 *
 * @param bool $die
 * @param bool $error_return
 * @return bool|string true, false or error message
 */
$ObjectModel->validateFields(bool $die = true, bool $error_return = false) : bool|string

/**
 * Checks if multilingual object field values are valid before database interaction.
 *
 * @param bool $die
 * @param bool $errorReturn
 * @return bool|string true, false or error message
 */
$ObjectModel->validateFieldsLang(bool $die = true, bool $errorReturn = false) : bool|string

OrderHistory

/**
 * Sets the new state of the given order.
 *
 * @param int $new_order_state
 * @param int/object $id_order
 * @param bool $use_existing_payment
 */
$OrderHistory->changeIdOrderState(int $new_order_state, int $id_order, bool $use_existing_payment = false) : void

Product

/**
 * Create product
 */
Product::__construct(?int $id_product = null, bool $full = false, ?int $id_lang = null, ?int $id_shop = null, ?Context $context = null)

/**
 * @param int $quantity DEPRECATED
 * @param string $supplier_reference DEPRECATED
 */
$Product->addCombinationEntity(float $wholesale_price, float $price, float $weight, float $unit_impact, float $ecotax, int $quantity, array $id_images, string $reference, int $id_supplier, string $ean13, int $default, ?string $location = null, ?string $upc = null, int $minimal_quantity = 1, array $id_shop_list = [], ?string $available_date = null, string $isbn = '', ?int $low_stock_threshold = null, bool $low_stock_alert = false, ?string $mpn = null) : bool

/**
 * Check if there is no default attribute and create it if not.
 */
$Product->checkDefaultAttributes() : bool

/**
 * Del all default attributes for product.
 */
$Product->deleteDefaultAttributes() : bool

/**
 * Delete product images from database.
 *
 * @return bool success
 */
$Product->deleteImages() : bool

/**
 * Get all available product attributes combinations.
 *
 * @param int $id_lang Language id
 * @param bool $groupByIdAttributeGroup
 *
 * @return array Product attributes combinations
 */
$Product->getAttributeCombinations(?int $id_lang = null, bool $groupByIdAttributeGroup = true) : array

/**
 * Get the default attribute for a product.
 *
 * @return int Attributes list
 */
Product::getDefaultAttribute(int $id_product, int $minimum_quantity = 0, bool $reset = false) : int

/**
 * Returns product price.
 *
 * @param int $id_product Product id
 * @param bool $usetax With taxes or not (optional)
 * @param int|null $id_product_attribute product attribute id (optional).
 *                                       If set to false, do not apply the combination price impact.
 *                                       NULL does apply the default combination price impact
 * @param int $decimals Number of decimals (optional)
 * @param int|null $divisor Useful when paying many time without fees (optional)
 * @param bool $only_reduc Returns only the reduction amount
 * @param bool $usereduc Set if the returned amount will include reduction
 * @param int $quantity Required for quantity discount application (default value: 1)
 * @param bool $force_associated_tax DEPRECATED - NOT USED Force to apply the associated tax.
 *                                   Only works when the parameter $usetax is true
 * @param int|null $id_customer Customer ID (for customer group reduction)
 * @param int|null $id_cart Cart ID. Required when the cookie is not accessible
 *                          (e.g., inside a payment module, a cron task...)
 * @param int|null $id_address Customer address ID. Required for price (tax included)
 *                             calculation regarding the guest localization
 * @param null $specific_price_output If a specific price applies regarding the previous parameters,
 *                                    this variable is filled with the corresponding SpecificPrice object
 * @param bool $with_ecotax insert ecotax in price output
 * @param bool $use_group_reduction
 * @param Context $context
 * @param bool $use_customer_price
 *
 * @return float Product price
 */
Product::getPriceStatic(int $id_product, bool $usetax = true, ?int $id_product_attribute = null, int $decimals = 6, ?int $divisor = null, bool $only_reduc = false, bool $usereduc = true, int $quantity = 1, bool $force_associated_tax = false, ?int $id_customer = null, ?int $id_cart = null, ?int $id_address = null, ?array &$specific_price_output = null, bool $with_ecotax = true, bool $use_group_reduction = true, ?Context $context = null, bool $use_customer_price = true, ?int $id_customization = null) : float

/**
 * Get all available products.
 *
 * @param int $id_lang Language id
 * @param int $start Start number
 * @param int $limit Number of products to return
 * @param string $order_by Field for ordering
 * @param string $order_way Way for ordering (ASC or DESC)
 *
 * @return array Products details
 */
Product::getProducts(int $id_lang, int $start, int $limit, string $order_by, string $order_way, bool|int $id_category = false, bool $only_active = false, ?Context $context = null) : array

/**
 * Update a product attribute.
 *
 * @param int $id_product_attribute Product attribute id
 * @param float $wholesale_price Wholesale price
 * @param float $price Additional price
 * @param float $weight Additional weight
 * @param float $unit
 * @param float $ecotax Additional ecotax
 * @param int $id_image Image id
 * @param string $reference Reference
 * @param string $ean13 Ean-13 barcode
 * @param int $default Default On
 * @param string $upc Upc barcode
 * @param string $minimal_quantity Minimal quantity
 * @param string $isbn ISBN reference
 * @param int|null $low_stock_threshold Low stock alert
 * @param bool $low_stock_alert send email on low stock
 * @param string $mpn MPN
 *
 * @return array Update result
 */
$Product->updateAttribute(int $id_product_attribute, float $wholesale_price, float $price, float $weight, float $unit, float $ecotax, array $id_images, string $reference, string $ean13, int $default, ?string $location = null, ?string $upc = null, ?int $minimal_quantity = null, ?string $available_date = null, bool $update_all_fields = true, array $id_shop_list = [], string $isbn = '', ?int $low_stock_threshold = null, bool $low_stock_alert = false, ?string $mpn = null) : bool

Product::updateDefaultAttribute(int $id_product) : int|false

Shop

/**
 * Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID).
 *
 * @param string $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
 *
 * @return array
 */
Shop::getContextListShopID(bool $share = false) : array

ShopGroup

/**
 * Return a group shop ID from group shop name.
 *
 * @param string $name
 *
 * @return int
 */
ShopGroup::getIdByName(string $name) : int

Stock

// @todo

StockAvailable

/**
 * For a given id_product and id_product_attribute sets the quantity available.
 *
 * @param $id_product
 * @param $id_product_attribute
 * @param $quantity
 * @param null $id_shop
 * @param bool $add_movement
 *
 * @return bool
 */
StockAvailable::setQuantity(int $id_product, int $id_product_attribute, int $quantity, ?int $id_shop = null, bool $add_movement = true) : bool

/**
 * For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity.
 *
 * @param int $id_product
 */
StockAvailable::synchronize(int $id_product, ?int $order_id_shop = null) : void|false

Tools

/**
 * Delete directory and subdirectories.
 *
 * @param string $dirname Directory name
 */
Tools::deleteDirectory(string $dirname, bool $delete_self = true) : bool

/**
 * Delete file.
 *
 * @param string $file File path
 * @param array $exclude_files Excluded files
 */
Tools::deleteFile(string $file, array $exclude_files = []) : void

/**
 * Depending on _PS_MODE_DEV_ throws an exception or returns a error message.
 *
 * @param string|null $errorMessage Error message (defaults to "Fatal error")
 * @param bool $htmlentities DEPRECATED since 1.7.4.0
 * @param Context|null $context DEPRECATED since 1.7.4.0
 * @return string
 * @throws PrestaShopException If _PS_MODE_DEV_ is enabled
 */
Tools::displayError(?string $errorMessage = null, ?bool $htmlentities = null, ?Context $context = null) : string

/**
 * Get all values from $_POST/$_GET.
 *
 * @return mixed
 */
Tools::getAllValues() : mixed

/**
 * Checks if a key exists either in $_POST or $_GET.
 *
 * @param string $key
 * @return bool
 */
Tools::getIsset(string $key) : bool

/**
 * Get the server variable REMOTE_ADDR, or the first ip of HTTP_X_FORWARDED_FOR (when using proxy).
 *
 * @return string $remote_addr ip of client
 */
Tools::getRemoteAddr() : string

/**
 * getShopDomainSsl returns domain name according to configuration and depending on ssl activation.
 *
 * @param bool $http if true, return domain name with protocol
 * @param bool $entities if true, convert special chars to HTML entities
 * @return string domain
 */
Tools::getShopDomainSsl(bool $http = false, bool $entities = false) : string

/**
 * Get token to prevent CSRF.
 *
 * @param string $token token to encrypt
 */
Tools::getToken(bool $page = true, ?Context $context = null) : string

/**
 * Get a value from $_POST / $_GET
 * if unavailable, take a default value.
 *
 * @param string $key Value key
 * @param mixed $default_value (optional)
 * @return mixed Value
 */
Tools::getValue(string $key, mixed $default_value = false) : mixed

/**
 * Hash password.
 *
 * @param string $passwd String to has
 * @return string Hashed password
 */
Tools::hash(string $passwd) : string

/**
 * Check if submit has been posted.
 *
 * @param string $submit submit name
 */
Tools::isSubmit(string $submit) : bool

/**
 * Random password generator.
 *
 * @param int $length Desired length (optional)
 * @param string $flag Output type (NUMERIC, ALPHANUMERIC, NO_NUMERIC, RANDOM)
 * @return bool|string Password
 */
Tools::passwdGen(int $length = 8, string $flag = 'ALPHANUMERIC') : string|false

/**
 * Redirect user to another page.
 *
 * @param string $url Desired URL
 * @param string $base_uri Base URI (optional)
 * @param Link $link
 * @param string|array $headers A list of headers to send before redirection
 */
Tools::redirect(string $url, string $base_uri = __PS_BASE_URI__, ?Link $link = null, ?string|array $headers = null) : void

/**
 * 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.
 *
 * @param string $str
 * @return string
 */
Tools::str2url(string $str) : string

Zone

/**
 * Get a zone ID from its default language name.
 *
 * @param string $name
 * @return int id_zone
 */
Zone::getIdByName(string $name) : int

/**
 * Get all available geographical zones.
 *
 * @param bool $active
 * @param bool $activeFirst
 * @return array Zones
 */
Zone::getZones(bool $active = false, bool $activeFirst = false) : array
@javierrojas10
Copy link
Copy Markdown

Hi! great list! You should add StockAvailable::synchronize(int $id_product); needed when a product has combinations for example to sum them at the parent product.
Line 131

Best regards

@rseon
Copy link
Copy Markdown
Author

rseon commented Jul 6, 2021

Hi ! Thanks for your interest !
I am currently updating this list with more useful methods that I have found (and updated for PS 1.7), and will post it asap.

Thanks for this method !

@lucnap
Copy link
Copy Markdown

lucnap commented Aug 2, 2022

Great reference! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment