Child pages
  • Controllers within PrestaShop

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Controllers within PrestaShop

Table of Contents

In the an MVC architecture, a Controller manages the synchronization events between the View and the Model, and keeps them up to date. It receives all the user events and triggers the actions to perform.
If an action needs data to be changed, the Controller will "ask" the Model to change the data, and in turn the Model will notify the View that the data has been changed, so that the View can update itself.

All of PrestaShop's controllers actually override the Controller class through another inheriting class, such as :

  • AdminController,
  • ModuleAdminController,
  • FrontController,
  • ModuleFrontController,

...

They can be found in the /classes/controller folder.

The FrontController class

Some Here are some of the class' properties:

PropertyDescription
$templateTemplate name for page content.
$css_filesArray list of CSS files.
$js_filesArray list of JavaScript files.
$errorsArray of errors that have occurred.
$guestAllowedWhether a customer who has signed out can access the page.
$initializedWhether the init() function has been called.
$isoThe ISO code of the currently selected language.
$nThe number of items per page.
$orderByThe field used to sort.
$orderWayWhether to sort is ascending or descending ("ASC" or "DESC").
$pThe current page number.
$ajaxIf the ajax parameter is detected in request, set this flag to true.

Execution order of the controller's functions

  1. __contruct(): Sets all the controller's member variables.
  2. init(): Initializes the controller.
  3. setMedia() or setMobileMedia(): 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).
  4. postProcess(): Handles ajaxProcess.
  5. initHeader(): Called before initContent().
  6. initContent(): Initializes the content.
  7. initFooter(): Called after initContent().
  8. display() or displayAjax(): Displays the content.

Existing front-office controllers

Here is the default controllers, and the theme files that use them .

Controller's filenameDescription
AddressController.phpUsed by address.php to edit a customer's address.
AddressesController.phpUsed by addresses.php to get customer's addresses.
AttachmentController.php 
AuthController.phpUsed by authentication.php for customer login.
BestSalesController.phpUsed by best-sales.php to get best-sellers.
CartController.phpUsed by cart.php to manage the customer's cart.
CategoryControllerUsed by category.php to get product categories.CMSController
ChangeCurrencyController.php 
CmsController.phpUsed by cms.php to get a CMS page.
CompareController.phpUsed by products-comparison.php to compare products.
ContactController.phpUsed by contact-form.php to send messages.
DiscountController.phpUsed by discount.php to get a customer's vouchers.
GetFileController.php 
GuestTrackingController.phpUsed by guest-tracking.php to manage guest orders.
HistoryController.phpUsed by history.php to get a customer's orders.
IdentityController.phpUsed by identity.php for customer's personal info.
IndexController.phpUsed by index.php to display the homepage.
ManufacturerController.phpUsed by manufacturer.php to get manufacturers.
MyAccountController.phpUsed by my-account.php to manage customer account.
NewProductsController.phpUsed by new-products.php to get new products.
OrderConfirmationController.phpUsed by order-confirmation.php for order confirmation.
OrderController.phpUsed by order.php to manage the five-step checkout.
OrderDetailController.phpUsed by order-detail.php to get a customer order.
OrderFollowController.phpUsed by order-follow.php to get a customer's returns.
OrderOpcController.phpUsed by order-opc.php to manage one-page checkout.
OrderReturnController.phpUsed by order-return.php to get a merchandise return.
OrderSlipController.phpUsed by order-slip.php to get a customer's credit slips.
PageNotFoundController.phpUsed by 404.php to manage the "Page not found" page.
ParentOrderController.phpManages shared order code.
PasswordController.phpUsed by password.php to reset a lost password.
PdfInvoiceController.php 
PdfOrderReturnController.php 
PdfOrderSlipController.php 
PricesDropController.phpUsed by prices-drop.php to get discounted products.
ProductController.phpUsed by product.php to get a product.
SearchController.phpUsed by search.php to get search results.
SitemapController.phpUsed by sitemap.php to get the sitemap.
StatisticsController.php 
StoresController.phpUsed by stores.php to get store information.
SupplierController.phpUsed by supplier.php to get suppliers.

Overriding a controller

Thanks to object inheritance, you can change a controller's behaviors, or add new ones.

...