prestashop4

How to make a Prestashop module (1/X)

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Introduction

Prestashop is a quite recent ecommerce Open source project that aims high, as is well demonstrated by the prize with which it has been awarded recently, the Open-Source Award 2010.

Is a very complete and easy installing solution….but, how can I extend its functionalities?, by the means of its powerfull modularity, of course, but….. how do I made a module, where do I start?

The documentation regarding it is rather limited, and there is where this post comes in. Before we get down to work, I would make it clear that certain necessary knowledge is required to develop the module, as MySql,Php and the Smarty template engine .

Prestashop is based on the MVC model (Model View Controller) to handle the information.

Model->all the objects that extend the base class “ObjectModel”, which defines the standard functions and behaviour to manage all the Prestashop tables, the CRUD (Create,Read,Update and Delete) and the multilingual support basis.

View->Implemented through the Smarty templates, which take care of managing the screen data presentation.

Controller->The classes which manage the data flow, retrieving data from the model and sending them to the view.They’re found on the root folder of the application and they match to the main pages of the application.

Given the fact that any change on that architecture would be highly hard to control and update with the different new versions of the product, the solution lies in modules creation, since they use the functions and resources of the application core, without interferring with it.

Creation of the files that made up the module

First thing to have in mind is the Prestashop nomenclature, the name of the class into the file can be capitalized “MiClass”, however, the file wich contains the class as the module folder must be named completely lowercases and equal to the class. We will name our folder “testmodule” and create it in “rootFolder/modules/”.

Then, we’ll create the “testmodule.php” file, which inherits from the “Module” base class:

<?php
Class testModule extends Module{
}
?>

Once created, the first method we must define is __construct(), which is the one responsible of reporting Prestashop all the info of the module.

<?php
Class testModule extends Module{
	function __construct(){
		$this->name = 'testmodule';
		$this->displayName = 'testModule';
		$this->tab = 'Blocks';
		$this->version = 1.0;
		$this->confirmUninstall = $this->l('Are you sure you want to uninstall testModule?');
		$this->description = $this->l('Example module, it does nothing by the time');
                $this->page = basename(__FILE__, '.php');
                parent::__construct();

	}
}
?>

name->module name (follows the same convention as the module folder, in lowercase)
displayName->name of the module to show
tab->tag in which we want our module to be listed in the BackOffice
version->module version
confirmUninstall->uninstallation confirmation message
description->short description of functionalities

With that we’ll have enough for our module to be shown on our shop’s module list.

Furthermore, if we include a “logo.gif” file in our module’s folder, it will be used as module logo when listing it on our shop.

Our module listen on the BackOffice

Our module listen on the BackOffice

With that we have the base structure of the module, now we have to make it display on the frontOffice (or in the back, depending on the functionality we want to implement) and make it actually do something.
We’ll see all those things later on, so watch out for the post’s second part.

  • Hector_ete

    Awesome post Mr Iskander. Im really sure that it will be usefull at my job.

    We are still waiting for the second part of the post.¿Are you escaqueanding?

    xoxo.

  • Hector_ete

    Sorry i wanted to say “the third part”, the second part is another amazing post that i read as well as you say.

    Anyway, dont you mind that prestashop module would be a tread to speak on a COFFE-TEC? Im sure that much people attend to your speech. We can record it on video too :D

    • http://steamcommunity.com/id/Bhardiel Igomez

      Well, not a bad idea at all, but first I must complete all the tutorial :P and it takes time…. :S

  • Hector_ete

    Ok, we are waiting for your complete tutorial. At least we’ll have something to read of prestashop.

    Thanks a lot PHP-ISK-MAN

    PS: i am freaking out with the fucking captcha but i already have got it .