Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 30 ยท Getting Started

What PrestaShop Is and How It Is Built

Learn what PrestaShop is, how modules and themes differ, how the legacy ObjectModel and Symfony layers fit together, and what PrestaShop 8 and 9 change.

PrestaShop is an open source e-commerce platform written in PHP. You install it on your own server, fill it with products, and it gives you a storefront for customers and an administration panel for the people who run the shop. Because the source code is open and the platform is built around modules, a large part of what a real PrestaShop shop does (payments, shipping rates, newsletters, product badges, ERP connections) is delivered by modules rather than by the core.

This course teaches you to write those modules. Before you write one, you need a mental map: what the platform consists of, where your code plugs in, and which parts are old and which are new. PrestaShop has been developed for many years, and it shows. Two different generations of code live side by side, and knowing which one you are looking at removes a lot of confusion. If you want the bigger picture of how online shops work in general, read What Is E-commerce? first; this lesson stays with PrestaShop itself.

PrestaShop cannot run on this website, because it needs PHP with a web server and a MySQL database. All real PrestaShop code in this course is shown in plain, read-only code blocks. Next to it, every lesson gives you runnable stand-ins: small PHP programs that you can edit and run here, which imitate the idea (a hook dispatcher, a module loader, a settings form) in a few lines. Each lesson says clearly what is real and what is the stand-in.

Modules, themes and the core

Three kinds of code make up a PrestaShop installation:

  • The core is the code that ships with PrestaShop: product, cart and order handling, the database layer, the back office and the front controllers. You do not edit it, because your changes would be lost at the next update.
  • Modules add or change behavior. A module is a folder under modules/ with a main PHP class. It can show a block on the product page, add a payment method, add a page to the back office, or react when an order is placed.
  • Themes control how the storefront looks. A theme is a folder under themes/ with Smarty templates, CSS and JavaScript. Themes also decide where in the page the hooks of modules are placed.

The rule of thumb: if a change is about behavior or data, it belongs in a module; if it is about how the page looks, it belongs in a theme. Modules can also ship their own templates, and a theme can override those templates without touching the module.

PrestaShop calls the customer-facing shop the front office and the administration panel the back office. You will see both terms constantly.

Two generations side by side

The core of PrestaShop was written long before Symfony existed in its current form. Starting with version 1.7, the project began moving to the Symfony framework piece by piece, but a full rewrite never happened. The result is a hybrid:

Layer Legacy code Modern code
Data classes ObjectModel classes such as Product, Cart, Order Doctrine entities and CQRS commands (in newer areas)
Front office pages Front controllers, Smarty templates Same (the front office is still legacy)
Back office pages Legacy admin controllers, some still with Smarty Symfony controllers with Twig templates and grids
Configuration Configuration::get() key-value store Symfony services and parameters

The front office is still mainly the legacy stack: a controller class in controllers/front/, a Smarty template, and ObjectModel classes underneath. The back office is split. Many pages (Orders, Catalog, Customers, Advanced Parameters) are Symfony pages with Twig, and some old pages still use the legacy admin controllers.

Modules are allowed to use both worlds, and in this course you will too. Lessons about hooks, front controllers and ObjectModel cover the legacy side, which is what most existing modules use. Later lessons cover The Symfony Back Office and Twig, Forms and Grids.

PrestaShop 8 and PrestaShop 9

You will meet two major versions in the wild.

  • PrestaShop 8.x is the long-running stable line. It runs on a Symfony 4.4 based back office and supports a range of PHP versions (check the official compatibility chart for the exact range of your minor version). Most shops and most third-party modules today target 8.
  • PrestaShop 9 moves to a newer Symfony version and a higher minimum PHP version, introduces a new default theme (Hummingbird) and adds an Admin API based on OAuth2 (see The Admin API in PrestaShop 9). Modules for 9 must usually declare compatibility explicitly.

Everything in this course is written so that the module basics work on both. Where a feature exists only in one version, the lesson says so. The golden rule: always check the version you actually run (the footer of the back office shows it, and so does the _PS_VERSION_ constant), and read the official upgrade notes before assuming that something from version 8 still works in 9.

When you search for help, add the version number to your query. A forum answer from 1.6 times (Smarty everywhere, AdminController for every page) is often wrong for today's shops.

How a front-office request flows

When a visitor opens a product page, PrestaShop does roughly this:

flowchart LR
    A["Browser requests /product-url"] --> B["Dispatcher<br/>(finds the controller)"]
    B --> C["ProductController<br/>(legacy front controller)"]
    C --> D["ObjectModel classes<br/>(Product, Cart ...)"]
    C --> E["Smarty template"]
    E --> F["Hooks: modules add HTML"]
    F --> G["HTML response"]

The dispatcher picks a front controller, which loads data through ObjectModel classes and renders a Smarty template. Along the way, hooks let modules add their own output.

The dispatcher maps the URL to a controller. The controller loads data (through ObjectModel classes that read from MySQL), assigns variables to Smarty, and renders a template. Inside the template, {hook h='displayProductAdditionalInfo'} calls mean: "ask every module that registered for this spot if it has something to show here". This is the main extension mechanism and the subject of the whole Hooks chapter.

The stand-in below shows the idea in miniature: a page is built by a "controller", and registered modules each add a piece of HTML at named hook points. Nothing in it is PrestaShop code; it only demonstrates the shape of the flow.

PHP A page assembled from hook points

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

The important point: the controller does not know which modules exist. It only knows the hook names. That loose coupling is why you can install and remove modules without editing the core.

Why the core is hard to change, and why that is good

Because PrestaShop has many versions, hosts and thousands of modules, the platform is designed so that you extend it instead of editing it:

  • Hooks let you add output or react to events.
  • Configuration stores module settings in the database.
  • Overrides let you replace a core class (powerful and risky; see Overrides vs Hooks).
  • Services and events in the Symfony part allow decoration and listening.

If you instead edit a core file, the next update either overwrites your change or breaks. This is the number one source of "my shop broke after the update" stories, so we treat the core as read-only throughout this course.

What a module looks like (preview)

Here is the smallest possible module. It is real PrestaShop code, so it is shown read-only; the next lessons explain every line.

PHP
<?php
// modules/hellomodule/hellomodule.php
if (!defined('_PS_VERSION_')) {
    exit;
}

class Hellomodule extends Module
{
    public function __construct()
    {
        $this->name = 'hellomodule';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Your Name';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->trans('Hello module', [], 'Modules.Hellomodule.Admin');
        $this->description = $this->trans('Says hello on the product page.', [], 'Modules.Hellomodule.Admin');
    }
}

A folder, one class that extends Module, and a handful of properties: that is all PrestaShop needs to list it in the back office. Everything else (hooks, settings pages, database tables) is added on top.

PHP Which layer handles this URL?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Treat that list as a thinking aid, not as documentation of the real router. The point is to train your eye: when you debug, first ask which layer a page belongs to.

Where to go from here

You now know the vocabulary: front office, back office, core, module, theme, hook, legacy versus Symfony. The next lesson sets up a local PrestaShop so that you can try the real code on your own machine, and the lessons after that build a module step by step. For general questions such as how to choose between platforms, see Choosing a Platform.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where should a change to the behavior of PrestaShop normally be made?

    Modules are the supported way to add or change behavior. Edits to core files are overwritten or conflict at the next update.
  2. 2. Which statement about the architecture of PrestaShop 8 is correct?

    The project migrated to Symfony step by step, so both generations live side by side. The front office is still mostly legacy front controllers and Smarty.
  3. 3. What does a hook point in a template mean?

    A hook is a named extension point. The core calls it and every module registered for it gets a chance to add output or act.
  4. 4. Why are the real PrestaShop code samples in this course read-only?

    The in-page runner executes single PHP files. PrestaShop itself needs a full installation, so the course pairs read-only real code with runnable stand-ins.

Summary

  • PrestaShop is an open source PHP shop platform: the core, modules for behavior, themes for appearance.
  • The front office is mostly legacy (front controllers, Smarty, ObjectModel); the back office mixes legacy pages and Symfony with Twig.
  • Hooks are named extension points that make modules loosely coupled to the core.
  • PrestaShop 8 and 9 differ in Symfony and PHP versions, theme and API; always check your version and the upgrade notes.
  • Never edit core files; extend with modules.
  • Real code is read-only here; stand-ins run on the site.

Next: Setting Up a Development Environment