Architecture

Table of contents

/*<![CDATA[*/ div.rbtoc1597330884914 {padding: 0px;} div.rbtoc1597330884914 ul {list-style: disc;margin-left: 0px;} div.rbtoc1597330884914 li {margin-left: 0px;padding-left: 0px;} /*]]>*/

Architecture

PrestaShop uses Model-View-Controller (MVC) for its software architecture, which is often used in web applications where webpages are dynamically generated. MVC isolates application logic from the input and presentation, so that they can be separately developed, tested and maintained. A view provides the user interface presented to the customer in the browser. A controller receives input from the browser, decides what to do with it and then passes information to models that carry out specific tasks. In PrestaShop, the models are in the /classes directory, the views are in the /themes directory and the controllers are in the /controllers directory. The files in the root directory are the public interface used to call the controllers.

All these files have a warning at the top of them telling you not to modify them if you wish to upgrade PrestaShop to newer versions in the future. That is because PrestaShop allows you to override its classes and controllers in the override directory. By overriding classes and controllers instead of modifying them, you can safely overwrite them with new versions in the future without having to worry about losing any changes you have made. PrestaShop’s modules also have the same warning, since they can be overridden in a theme by mirroring the module’s directory inside the theme, e.g. themes/themename/modules/blockuserinfo/blockuserinfo.tpl.

Models

The models in the /classes directory of PrestaShop are all PHP classes that extend the ObjectModel class. This class gives the model a unique ID and a table name and identifier to link it to a row in the database. For example, in the Address model, the ID is a positive integer, the table name is address and the table identifier is id_address. The ObjectModel class also defines the model’s field sizes and the functions in the Validate class that are used to validate fields. It also links the model to the webservice feature and provides a cache. The model class names all end in Core so they can be overridden in the /override/classes directory. Here is a description of each PrestaShop model:

Model Filename

Description

Address.php

Customer, manufacturer and supplier addresses.

AddressFormat.php

Address format for each country.

Alias.php

Aliases used to redirect typos in the search box in the Front Office.

Attachment.php

File attachments that are added to products.

Attribute.php

Product attributes that display as dropdowns on the product page.

AttributeGroup.php

Product attribute groups that display as labels for the dropdowns.

Carrier.php

Carriers used to ship products to customers.

Cart.php

Customer carts including those that didn’t result in an order.

Category.php

Product categories used to organise products.

CMS.php

CMS pages used to display information.

CMSCategory.php

Categories used to organise CMS pages.

Combination.php

Combinations of product attributes and their prices.

Configuration.php

All of PrestaShop’s configuration settings.

Connection.php

Statistics about page visits.

ConnectionsSource.php

Statistics about the source of page visits.

Contact.php

Departments that can be selected on the contact form.

Country.php

Countries used in addresses.

Currency.php

Currencies used in prices.

Customer.php

Customers who have registered.

CustomerMessage.php

Individual messages sent between customers and employees.

CustomerThread.php

Threads of messages sent between customers and employees.

DateRange.php

Date ranges used in page visits.

Delivery.php

Links between carriers, zones and ranges.

Discount.php

Vouchers that can be used by customers.

Employee.php

Employees who can log in to the Back Office.

Feature.php

Product feature labels on the product page.

FeatureValue.php

Product feature values on the product page.

Group.php

Customer groups and display methods.

GroupReduction.php

Customer group reductions.

Guest.php

Customers who haven’t registered.

Hook.php

Hooks where modules can be placed.

Image.php

Product images.

ImageType.php

Image thumbnail sizes.

Language.php

Languages used on the website.

Manufacturer.php

Product manufacturers.

Message.php

Customer messages sent from the order history page.

Meta.php

Meta-information of PrestaShop’s pages.

Order.php

Customer order information.

OrderDetail.php

Customer order products.

OrderDiscount.php

Customer order vouchers.

OrderHistory.php

Customer order status history.

OrderMessage.php

Prefilled order messages that employees can use.

OrderReturn.php

Merchandise returns.

OrderReturnState.php

Merchandise return statuses.

OrderSlip.php

Credit slips.

OrderState.php

Order statuses.

Pack.php

Product packs (extends Product class).

Page.php

PrestaShop’s non-CMS pages.

PaymentCC.php

Order credit card information.

Product.php

Product information.

ProductDownload.php

Downloadable products.

Profile.php

Profiles used to restrict employee access.

QuickAccess.php

Shortcuts in the dropdown at the top of the Back Office.

RangePrice.php

Carrier price ranges.

RangeWeight.php

Carrier weight ranges.

Referrer.php

Affiliate program data.

SearchEngine.php

Search engines tracked when guests visit.

Scene.php

Image maps that link products to banners.

Shop.php

Multiple shops (not yet implemented).

SpecificPrice.php

Specific prices including quantity discounts.

State.php

States used in addresses.

Store.php

Stores used in the store locator module.

StockMvt.php

Stock movements used to track employees’ changes.

StockMvtReason.php

Stock movement reasons.

SubDomain.php

Subdomains used by PrestaShop’s cookie.

Supplier.php

Product suppliers.

Tab.php

Back Office tabs and positions.

Tag.php

Product tags used by the tag cloud module.

Tax.php

Tax names and rates.

TaxRules.php

Specific tax rules.

TaxRulesGroup.php

Groups of the tax rules.

Webservice.php

External access to the database.

Zone.php

Zones used by the carriers.

Here’s a description of the other PrestaShop classes that do not store data in the database:

Class Filename

Description

AdminTab.php

Provides basic Back Office tab functionality.

Backup.php

Creates backups of the PrestaShop database.

Blowfish.php

Encrypts the PrestaShop cookie with Blowfish.

Cache.php

Provides basic caching functionality.

CacheFS.php

Perform File System caching.

CarrierModule.php

Provides basic shipping module functionality.

Chart.php

Creates charts.

ControllerFactory.php

Calls a controller and any overrides.

Cookie.php

Reads and writes PrestaShop’s cookie.

Customization.php

Gets product customization.

Db.php

Provides basic database functionality.

FrontController.php

Initialises Smarty variables and other basic controller code.

HelpAccess.php

Displays help tooltips and documentation.

ImportModule.php

Provides basic shop import functionality.

Link.php

Gets links to products, categories, CMS pages, etc.

LocalizationPack.php

Installs localisation packs.

Mail.php

Sends emails.

MCached.php

Performs Memcaching.

Module.php

Provides basic module functionality.

ModuleGraph.php

Provides module graph functionality.

ModuleGraphEngine.php

Provides module graph engine functionality.

ModuleGrid.php

Provides module grid functionality.

ModuleGridEngine.php

Provides module grid engine functionality.

MySQL.php

Provides access to a MySQL database.

PaymentModule.php

Provides basic payment module functionality.

PDF.php

Creates PDF invoices and delivery slips.

ProductSale.php

Manages product sale numbers.

Rijndael.php

Encrypts PrestaShop’s cookie using mcrypt.

Search.php

Performs searchs on products.

Validate.php

Validates data.

Here’s a description of the ObjectModel members:

Member Name

Description

$_cache

Stores a cache of all object.

$fieldsRequired

The required fields.

$fieldsRequiredDatabase

The required fields that have been overridden by an employee.

$fieldsSize

The maximum size of each non-translatable field.

$fieldsSizeLang

The maximum size of each translatable field.

$fieldsValidate

Array of validation functions that check non-translatable fields.

$fieldsValidateLang

Array of validation functions that check translatable fields.

$id

The integer ID of the object, e.g. 1

$identifier

The name of the ID of the object, e.g. id_address

$table

The main table used by the object.

$tables

All the tables used by the object.

$webserviceParameters

The webservice parameters for the object.

Here’s a description of the ObjectModel functions:

Function Name

Description

__construct()

Loads an object with the specified ID and language.

add()

Adds the current object to the database.

clearCache()

Used to clear the cache whenever an object is modified.

delete()

Deletes the current object from the database.

deleteSelection()

Deletes the specified list of objects from the database.

displayFieldName()

Gets the unique name of a field.

getFields()

Gets the non-translatable fields for the object.

getFieldsRequiredDatabase()

Gets the required fields overridden by an employee.

getTranslationFields()

Gets the translatable fields for the object.

getValidationRules()

Gets the validation rules for the object.

getWebserviceObjectList()

Gets a list of all webservice objects.

getWebserviceParameters()

Gets the webservice parameters for the object.

save()

Saves the object, adding it or updating it as necessary.

toggleStatus()

Toggles whether the object is visible on the website.

update()

Updates the current object in the database.

validateController()

Checks whether required fields have valid data.

validateFields()

Checks whether required non-translatable fields have valid data.

validateFieldsLang()

Checks whether required translatable fields have valid data.

Here’s a description of the validation functions:

Function Name

Description

isAbsoluteUrl()

Is an absolute URL (e.g., http://www.domain.com).

isAddress()

Is an address line (^!<>?=+@{}_$% not allowed).

isAnything()

Accepts anything without doing any validation.

isBirthDate()

Is empty date or a date in yyyy-mm-dd format at least 9 years ago.

isBool()

Is a Boolean value 0 or 1.

isBool_Id()

Is a Boolean id (0 or 1 followed by an underscore, then digits).

isCarrierName()

Is a valid carrier name (^<>;=#{} not allowed).

isCatalogName()

Is a catalog name (^<>;=#{} not allowed).

isCityName()

Is a city name (^!<>;?=+@#"°{}_$% not allowed).

isCleanHtml()

Is HTML without script tags or events.

isColor()

Is a colour keyword or hexadecimal code.

isConfigName()

Is a configuration key (alphanumeric and hypens).

isCookie()

Is an instance of the Cookie class.

isCoordinate()

Is a coordinate (up to 6 digits, a period, then up to 6 digits).

isCountryName()

Is a country name (lowercase letters, spaces and hyphens).

isDate()

Is a date in yyyy-mm-dd format.

isDateFormat()

Is a valid date in yyyy-mm-dd format.

isDiscountName()

Is a valid voucher code (3-32 characters except ^!<>,;?=+()@"°{}_$%:).

isDistanceUnit()

Is a distance unit (up to 2 letters).

isDni()

Is a valid DNI, NIF, CIF or NIE code and return an error code (deprecated).

isDniBool()

Whether an error code was returned from isDni (deprecated).

isEan13()

Is a 13-digit EAN13 code.

isEmail()

Is an email of the form username@domain.tld.

isFileName()

Is a valid filename (alphanumeric, hyphens, underscores and periods).

isFloat()

Is a valid float value.

isGenderIsoCode()

Is a valid gender ISO code (0, 1 [male], 2 [female] or 9 [unknown]) (deprecated).

isGenderName()

Is a valid gender name (lowercase alphanumeric and period) (deprecated).

isGenericName()

Is a generic name (^<>;=#{} not allowed).

isGranularityValue()

Is a date format using lowercase d, m and y (deprecated).

isHookName()

Is a valid hook name (lowercase alphanumeric and hyphens).

isImageSize()

Is an image size (up to 4 digits).

isIcoFile()

Is a valid filename ending in .ico (deprecated).

isIconFile()

Is a valid filename ending in .gif, .jpg, .jpeg or .png (deprecated).

isImageTypeName()

Is a valid image type name (lowercase alphanumeric, spaces and hyphens).

isInt()

Is an integer.

isIp2Long()

Is a valid IP address.

isLabel()

Is a customisation field label (^{}<> allowed).

isLangIsoCode()

Is a language iso code (2 or 3 alphanumeric).

isLanguageFileName()

Is a language filename (2 or 3 alphanumeric followed by .gzip).

isLanguageIsoCode()

Is a valid language ISO code (2 or 3 lowercase letters).

isLinkRewrite()

Is a rewritten link (lowercase alphanumeric, hypens and underscores).

isLoadedObject()

Is a variable is an object and has a valid ID.

isLocalizationPackSelection()

Is "states", "taxes", "currencies", "languages" or "units".

isMailName()

Is a valid mail name (^<>;=#{} not allowed).

isMailSubject()

Is a valid mail subject (^<>{} not allowed).

isMessage()

Is a message (<>{} not allowed except <br />).

isMd5()

Is a valid MD5 hash.

isModuleName()

Is a valid module name (lowercase alphanumeric and hyphens).

isModuleUrl()

Is a valid URL to a zip, tgz or tar.gz file.

isName()

Is a valid name (^0-9!<>,;?=+()@#"°{}_$%: not allowed).

isOptFloat()

Is an empty field or valid float value.

isOptId()

Is an empty field or a positive integer (deprecated).

isOrderWay()

Is a valid order way 'ASC', 'DESC', 'asc' or 'desc'.

isOrderBy()

Is a valid order (lowercase alphanumeric, hyphens and underscores).

isPasswd()

Is a customer password (5-32 alphanumeric and (). -!@#$%\^&*).

isPasswdAdmin()

Is an employee password (8-32 alphanumeric and (). -!@#$%\^&*).

isPostCode()

Is a postcode (alphanumeric and hyphens).

isPrice()

Is a valid price (up to 10 digits, a period, then up to 9 digits).

isPriceDisplayMethod()

Is a price display method (must be PS_TAX_EXC or PS_TAX_INC values).

isProtocol()

Is the protocol http or https (deprecated).

isReductionType()

Is a reduction type "amount" or "percentage".

isReference()

Is a reference (^<>;={} not allowed).

isSerializedArray()

Is a serialised array.

isSha1()

Is a valid SHA1 hash.

IsSortDirection()

Is a sort direction 'ASC' or 'DESC'.

isStateIsoCode()

Is a valid state ISO code (up to 4 lowercase alphanumeric).

isString()

Is a string.

isSubDomainName()

Is a subdomain name.

isTableOrIdentifier()

Is a table name (lowercase alphanumeric, hyphens and underscores).

isTabName()

Is a valid tab name (alphanumeric, hyphens and underscores).

isTagsList()

Is a tags list (^!<>;?=+#"°{}_$% not allowed).

isTplFileName()

Is a valid template filename (alphanumeric, hyphens and underscores) (deprecated).

isTplName()

Is a valid template name (lowercase alphanumeric and hyphens).

isUnsignedFloat()

Is a valid positive float value.

isUnsignedId()

Is a positive integer.

isUnsignedInt()

Is a positive integer.

isUrl()

Is a valid URL.

isUpc()

Is a 12-digit UPC code.

isValidSearch()

Is a valid search (up to 64 characters except ^<>;=#{}).

isValuesList()

Is a MySQL query values list (deprecated).

isVoucherDescription()

Is a voucher description (<>{} not allowed except <br />).

isWeightUnit()

Is a weight unit (up to 3 letters).

isZipCodeFormat()

Is a zip code format (using uppercase letters N, L, C, spaces and hyphens).

isZoneName()

Is a zone name (lowercase letters, hyphens, spaces and parentheses) (deprecated).

Views

PrestaShop uses Smarty templating for its views, which supplements HTML with a flexible syntax to add variables, if statements, loops and other PHP code to the view. Most of the TPL files have the same name as the PHP file that calls them. For example, 404.php calls 404.tpl. Here is a description of PrestaShop’s templates:

View Filename

Description

404.tpl

The “Page not found” page.

address.tpl

The address form.

addresses.tpl

Lists customer addresses.

authentication.tpl

The login and registration forms.

best-sales.tpl

Lists the best-selling products.

breadcrumb.tpl

The breadcrumb bar at the top of the centre column.

category-cms-tree.tpl

Used by sitemap.php to list CMS pages on the sitemap.

category-tree-branch.tpl

Used by sitemap.php to list subcategories on the sitemap.

category.tpl

Lists a category’s subcategories and products.

cms.tpl

Displays a CMS page.

contact-form.tpl

The customer service contact form.

discount.tpl

Lists vouchers available to a customer.

errors.tpl

Displays error messages.

footer.tpl

The footer at the bottom of the website.

guest-tracking.tpl

The guest order tracking form.

header.tpl

The header at the top of the website.

history.tpl

Lists a customer’s orders.

identity.tpl

The customer’s personal information form.

index.tpl

The center column on the homepage.

maintenance.tpl

The maintenance page when the shop is disabled.

manufacturer-list.tpl

Lists manufacturers.

manufacturer.tpl

Lists the products of a manufacturer.

my-account.tpl

The account page of a customer.

new-products.tpl

Lists new products.

order-address.tpl

Used by order.php and order-opc.php for the address step.

order-carrier.tpl

Used by order.php and order-opc.php for the carrier step.

order-confirmation.tpl

The order confirmation page.

order-detail.tpl

Used by guest-tracking.php and history.php for order details.

order-follow.tpl

Lists a customer’s merchandise returns.

order-opc.tpl

The one-page checkout page.

order-opc-new-account.tpl

Used by order-opc.php for the login and new account forms.

order-payment.tpl

Used by order-opc.php for the payment step.

order-return.tpl

Displays information about a merchandise return.

order-slip.tpl

Lists a customer’s credit clips.

order-steps.tpl

Used by order.php to display the order steps.

pagination.tpl

The page navigation at the bottom of the centre column.

password.tpl

The lost password form.

prices-drop.tpl

Lists discounted products.

product-compare.tpl

Adds product comparison checkboxes to the product listings.

product-list.tpl

Lists products.

product-sort.tpl

The “Sort by” form at the top of product listings.

product.tpl

Information about a product.

products-comparison.tpl

The product comparison page.

restricted-country.tpl

Displays a message when a customer has been restricted by country.

scenes.tpl

Used by category.php to display banners that link to products.

search.tpl

List the search results page.

shopping-cart-product-line.tpl

Used by shopping-cart.tpl to display a product line in the cart summary.

shopping-cart.tpl

Used by order.php and order-opc.php to display the cart summary.

sitemap.tpl

The sitemap of the website.

store_infos.tpl

The store opening hours.

stores.tpl

The store information and Google map.

supplier-list.tpl

Lists suppliers.

supplier.tpl

Lists products from a supplier.

Controllers

Here’s a list of PrestaShop’s controllers and a description of what each of them do:

Controller Name

Description

AddressController.php

Used by address.php to edit a customer’s address.

AddressesController.php

Used by addresses.php to get a customer’s addresses.

AuthController.php

Used by authentication.php to manage customer login.

BestSalesController.php

Used by best-sales.php to get the best-selling products.

CartController.php

Used by cart.php to manage the customer’s cart.

CategoryController.php

Used by category.php to get product categories.

CMSController.php

Used by cms.php to get a CMS page.

CompareController.php

Used by products-comparison.php to compare products.

ContactController.php

Used by contact-form.php to send messages to employees.

DiscountController.php

Used by discount.php to get vouchers available to a customer.

GuestTrackingController.php

Used by guest-tracking.php to manage guest orders.

HistoryController.php

Used by history.php to get a customer’s orders.

IdentityController.php

Used by identity.php to get a customer’s personal information.

IndexController.php

Used by index.php to display the homepage.

ManufacturerController.php

Used by manufacturer.php to get manufacturers and their products.

MyAccountController.php

Used by my-account.php to display a customer’s account page.

NewProductsController.php

Used by new-products.php to get a list of new products.

OrderConfirmationController.php

Used by order-confirmation.php to manage the order confirmation page.

OrderController.php

Used by order.php to manage the five-step checkout pages.

OrderDetailController.php

Used by order-detail.php to get a single customer order.

OrderFollowController.php

Used by order-follow.php to get a list of a customer’s merchandise returns.

OrderOpcController.php

Used by order-opc.php to manage the one-page checkout page.

OrderReturnController.php

Used by order-return.php to get a single merchandise return.

OrderSlipController.php

Used by order-slip.php to get a list of a customer’s credit slips.

PageNotFoundController.php

Used by 404.php to manage the “Page not found” page.

ParentOrderController.php

Used by OrderController.php and OrderOpcController.php for shared code.

PasswordController.php

Used by password.php to allow a customer to reset a lost password.

PricesDropController.php

Used by prices-drop.php to get a list of discounted products.

ProductController.php

Used by product.php to get a product.

SearchController.php

Used by search.php to perform a search and get the results.

SitemapController.php

Used by sitemap.php to get the sitemap of the website.

StoresController.php

Used by stores.php to get store information and Google map coordinates.

SupplierController.php

Used by supplier.php to get suppliers and their products.

All controllers in PrestaShop extend the FrontController class. Here’s a description of the FrontController members:

Member Name

Description

$auth

Whether a customer must log in before they can access the page.

$authRedirection

The page redirected to after logging in.

$cart

The current customer’s or guest’s cart.

$cookie

Used to access PrestaShop’s cookie variables.

$currentCustomerGroups

Caches the current customer’s groups.

$errors

An array of errors that have occurred.

$guestAllowed

Whether a customer who has signed out can access the page.

$initialized

Whether the init() function has been called.

$iso

The iso code of the currently selected language.

$link

Used to generate PrestaShop links.

$n

The number of items per page.

$orderBy

The field used to sort.

$orderWay

Whether to sort ascending or descending ("ASC" or "DESC").

$p

The current page number.

$smarty

Used to access Smarty variables and functions.

$ssl

Whether the page is loaded using SSL when it is available.

Here’s a description of the controller functions in the order they are executed:

Function Name

Description

__construct()

Sets all the controller’s member variables.

preProcess()

Assigns variables that can be used in the header template file.

setMedia()

Adds all JavaScript and CSS specific to the page so it can be combined, compressed and cached.

displayHeader()

Calls the header template file.

process()

Assigns variables that can be used by the content template file.

displayContent()

Calls the content template file.

displayFooter()

Calls the footer template file.

Last updated