PrestaShop Modules Standard Functions. Version 1.2.5
Standard Prestashop Module Functions
Prestashop uses a system of plug in modules to add new functionality to the basic "default" install. For example it will allow a store owner to add a new payment or shipping module. To assist a developer in creating modules the plugin system has a set of standard functions. I have found some and am listing them here. As I discover more I will add them to this document. I hope they prove useful to others.
function __construct()
This essential "constructor" function issued to setup the module with some startup parameters. For example its name version and description. See below for an example:
public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'Shipping'; // Where this module will appear in the admin screen.
$this->version = '1.2'; // Set the version number
parent::__construct();
$this->displayName = $this->l('My Account block'); // the name that is displayed in the adminstration screen
$this->description = $this->l('Displays a block with links relative to user account'); // a breif description that is displayed in the administration screen
}function __install()
This is the function that is called when a modules install button is clicked.
This is where you code to setup the module. For example you might register the module with hooks (prestashop is broken up into distinct parts, such as payment shipping or invoice you can "hook" into these). You declare the parts you wish to hook into in this function. See below for a basic install function - this is taken from the myAccount module which displays in the left column of prestashop. As you can see it registers with the left column hook of the store.
public function install()
{
if (!$this->addMyAccountBlockHook() OR !parent::install() OR !$this->registerHook('leftColumn'))
return false;
return true;
}Other things you might do in the install() function is run SQL code to add or alter tables if the module requires it.
For example look at this code from the sekeywords. It creates a table called
sekeyword
function install()
{
if (!parent::install() OR !$this->registerHook('top') OR !$this->registerHook('AdminStatsModules'))
return false;
return Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'sekeyword` (
id_sekeyword INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
keyword VARCHAR(256) NOT NULL,
date_add DATETIME NOT NULL,
PRIMARY KEY(id_sekeyword)
) ENGINE=MyISAM DEFAULT CHARSET=utf8');
}function uninstall()
This function is run when the modules uninstall link is clicked. If the function is correctly processed then the administrator will recieve a message telling them that the module has been removed.
The example below is from the sekewords and as you can see if removes the table added by the install function.
function uninstall()
{
if (!parent::uninstall())
return false;
return (Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'sekeyword`'));
}
