Creating a new prestashop modules is not difficult as it seems. To create a simple module there are 4 easy steps to follow.
Let us create an image slider for the home page
1. Add a new row for the new module in the ps_module table
name: blockslider
active: 1
2. Create the .php file
Create a folder named blockslider in the prestashop modules directory and create blockslider.php file within the directory with below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
if (!defined('_PS_VERSION_')) exit; class BlockSlider extends Module { public function __construct() { $this->name = 'blockslider'; $this->tab = 'front_office_features'; $this->version = 0.1; $this->author = 'Your Name'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Slider block'); $this->description = $this->l('Adds a block for featured products slider.'); } /** * process installing */ function install(){ if (!parent::install()) return false; if(!$this->registerHook('home')) return false; return true; } function hookHome($params) { return $this->processHook( $params,"home"); } function processHook($pparams, $pos="home"){ global $smarty; //load param $params = $this->_params; return $this->display(__FILE__, 'blockslider.tpl'); } } |
3. Create the .tpl file
Here you can use any JQuery based slider or create your own. Just remember to copy the relevant JS and CSS files along with any images to the modules folder and just call the JS and CSS files in the .tpl file.
Create blockslider.tpl file in the same directory as above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<a href="http://PATH_TO_YOUR_JS">http://PATH_TO_YOUR_JS</a> <link href="PATH_TO_YOUR_CSS" rel="stylesheet" type="text/css" media="all" /> $(function(){ $('#slider').startSlider(); }); <div style="clear:both;margin-bottom:30px;"> <ul id="slider"> <li><img src="PATH_IMAGE_1" alt=""></li> <li><img src="PATH_IMAGE_2" alt=""></li> <li><img src="PATH_IMAGE_3" alt=""></li> </ul> </div> |
4. Transplant the module
Once the module is created, it will appear in the Front Office Features section.
Make sure it is installed and enabled
Just transplant the module to Homepage content