Child pages
  • Creating a PrestaShop module

Versions Compared

Key

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

...

The front-office part of the module is defined in a .tpl file placed at the root of the module's folder. TPL files can have just about any name. It there's only one such file, it is good practice to give it the same name as the folder and main file: mymodule.tpl.

The mymodule.php file must start with the following test:

Code Block

if ( !defined( '_PS_VERSION_' ) )
  exit;

This checks for the existence of a PHP constant, and if it doesn't exist, it quits. The sole purpose of this is to prevent visitors to load this file directly.

It must also contain the module's class. PrestaShop is Object-Oriented Programming, and so does its modules.
That class must bear the same name as the module and its folder, in CamelCase: MyModule.
Furthermore, that class must extend the Module class, and thus inherits all methods and attributes. It can just as well extend any class derived from Module: PaymentModule, ModuleGridEngine, ModuleGraph...

Code Block
titlemymodule.php
borderStylesolid
<?php
if ( !defined( '_PS_VERSION_' ) )
  exit;

class MyModule extends Module
  {
  public function __construct()
    {
    $this->name = 'mymodule';
    $this->tab = 'Test';
    $this->version = 1.0;

    parent::__construct();

    $this->displayName = $this->l( 'My module' );
    $this->description = $this->l( 'Description of my module.' );
    }

  public function install()
    {
    if ( parent::install() == false )
      return false;
    return true;
    }
  }
?>

...