Posted on March - 07 - 2010
Prestashop: Module editing tutorial
Hi All!
It’s very easy to edit modules that displays different things on your prestashop store. The output of a module is generated by template files (.tpl). If you browse the folder of a module, you will see a ‘.tpl’ file for that module. You can play with it to show different information. This lesson is intended for people having no programming knowledge.
For very simple modification you won’t need to know anything almost. But if you want to show information based on your data stored in the database or some calculation, you will need to know a basic idea of php, smarty, and mysql. They all have crash courses which are sufficient for most of the cases. You cannot rely on others to send you the modifications throughout your life for free. It’s really tiring.
So I am giving you an example of how to edit a module’s output. Let’s take blockspecials module. Go to modules folder in your prestashop installation. Look for blockspecials folder. Then open 2 files namely ‘blockspecials.php’ and ‘blockspecials.tpl’. Our goal is to show a large image for the special product.
step1> Look for these code at the bottom of the .php file :
if ($special = Product::getRandomSpecial(intval($params['cookie']->id_lang)))
$smarty->assign(array(
'special' => $special,
'oldPrice' => number_format($special['price'] + $special['reduction'], 2, '.', ''),
//'mediumSize' => Image::getSize('medium')));
'mediumSize' => Image::getSize('home')));
step2> Now look closely at line 5,6. I have commented out line 5 which is the actual line in the original code and I added another line which is now line 6. This line assigns size (a number usually 129) of ‘home’ images in the smarty variable called ‘mediumSize’ which we will be able to print in our .tpl file. Home images are bigger than medium images. variable name doesn’t matter, rather its value.
step3> Now we go to .tpl file. I added a line of code at the top
{assign var='changeSize' value=30}
I created this smarty variable, changeSize, and set the image dimension to be calculated dependent on it so that I can later change its value and adjust the special products size. Square pictures are assumed. If you want rectangular pictures you need to do more calculation like this.
step3> then I changed the following line
<dt class="product_image">
into
<dt class="product_image" style='border:2px solid gray;padding:2px 2px 0px 2px;'>
this line adds a nice border around the image.
step4>Now we fetch the image with ‘home’ size instead of ‘medium’ size. Some smarty code again.
I replaced this line
<img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'medium')}" alt="{$special.legend|escape:htmlall:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$special.name|escape:htmlall:'UTF-8'}" />
with
<img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'home')}" alt="{$special.legend|escape:htmlall:'UTF-8'}" height="{$mediumSize.height+$changeSize}" width="{$mediumSize.width+$changeSize}" title="{$special.name|escape:htmlall:'UTF-8'}" />
Note the changes. The first change is in the ‘getImageLink’ function I changed the image size from ‘medium’ to ‘home’. This will cause the script to fetch the link to ‘home’ image of the product instead of ‘medium’ one. The second change is in the ‘height’ and ‘width’ attributes of the image. I just added the changeSize amount to those.
That’s all. You can download the modified module from www.prestaworld.com My advice for you is to have a 1 page smarty crash course from here and start playing with prestashop modules.









































