In this fun-sized tutorial, I’m going to cover the PrestaShop Canvas Module. This significant code can be of great use to you once you are all up-to-speed.
So then let’s have a look, shall we?
Step #1:
In the following directory, make a directory with a name that is identical to the name of your module.
basedir/modules
I have named my module helloworld and so the name in the directory will also reflect helloworld. Once this is done, the structure should look something like this:
basedir/modules/helloworld
Step #2:
Next, name the file helloworld.php in the location mentioned below. Make sure the name of your module directory is the same as the file.
basedir/modules/helloworld/helloworld.php
This file should include the following code.
<?php
if (!defined('_PS_VERSION_'))
exit;
class Helloworld extends Module
{
private $errors = null;
public function __construct()
{
// Author of the module
$this->author = 'addify';
// Name of the module ; the same that the directory and the module ClassName
$this->name = 'helloworld';
// Tab where it's the module (administration, front_office_features, ...)
$this->tab = 'others';
// Current version of the module
$this->version = '1.0.0';
// Min version of PrestaShop wich the module can be install
$this->ps_versions_compliancy['min'] = '1.5';
// Max version of PrestaShop wich the module can be install
$this->ps_versions_compliancy['max'] = '1.7';
// OR $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
// The need_instance flag indicates whether to load the module's class when displaying the "Modules" page
// in the back-office. If set at 0, the module will not be loaded, and therefore will spend less resources
// to generate the page module. If your modules needs to display a warning message in the "Modules" page,
// then you must set this attribute to 1.
$this->need_instance = 0;
// Modules needed for install
$this->dependencies = array();
// e.g. $this->dependencies = array('blockcart', 'blockcms');
// Limited country
$this->limited_countries = array();
// e.g. $this->limited_countries = array('fr', 'us');
parent::__construct();
// Name in the modules list
$this->displayName = $this->l('Example');
// A little description of the module
$this->description = $this->l('Module Example');
// Message show when you wan to delete the module
$this->confirmUninstall = $this->l('Are you sure you want to delete this module ?');
if ($this->active && Configuration::get('EXAMPLE_CONF') == '')
$this->warning = $this->l('You have to configure your module');
$this->errors = array();
}
}
And you’re done. Well, that was simple, right?
The article ends here, but learning never does. I’m a strong believer of exploring improvement opportunities which is why I look forward to your feedback and/or suggestions.
Feel free to let me know what’s on your mind. Cheers!