Header

How to create a Prestashop module with minic skeleton

First of all i would like to inform you that this is my very first tutorial and blog post as well. I`m not a writer so do not expect a high quality for now :)

This is a simple Prestashop module creation tutorial intorduce the advantages of our skeleton module. We created this module to speed up our module development process, because starting from the ground can take away lots of time.

Before we start you should

read the following from the Prestashop documentation:
Coding standards
– Setting up your local development environment
– Creating a PrestaShop module
– Hooks in PrestaShop 1.5
– Translations in PrestaShop 1.5
– and you can check the Developer tutorials

You might think this is a lot to read, but believe me, isn’t. If you don’t know these basic things about Prestashop development you can turn and do not waste your time with this short tutorial.

Lets start

I assume you have a development environment and a good text editor (I use Sublime Text 2).

So lets download the module,  can be found on our blog (here) on the Prestashop forum and on Github (if you downloaded from Github you have to rename the unzipped folder, remove the -master from the end of the folder name).

After download, unzip the content of the .zip file, and move it into your Prestashop modules folder, go to the backend of you store and you already can see that the module is there.

You can install if you want and see, that its working well, of course there are no configuration for the module.

Renaming / Replacing

If you wish, and you should, you have to rename the module. This mean a little search & replace job, with a good text editor can be done within no time.

First of all lets rename the module folder and module class (if you installed the module then uninstall it now).

Go into the module folder and rename the minicskeleton folder, here i`ll call it minictutorial. When you are done, browse the folder and you should rename 4 files:

  1. minicskeleton.php – located in the root of the module folder
  2. minicskeleton.css – located in the views/css/ folder
  3. minicskeleton.js – located in the views/js/ folder
  4. minicskeleton.tpl – located in the views/templates/admin/ folder

Now open the newly renamed php file, and change the class name.

class MinicTutorial extends Module

Do no close the file, there are other places where you should replace the name. Go and start with the  __construct() function.

public function __construct()
{
    $this->name = 'minictutorial';
    $this->tab = 'front_office_features';
    $this->version = '1.0';
    $this->author = 'minic studio';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
    // $this->dependencies = array('blockcart');

    parent::__construct();

    $this->displayName = $this->l('Minic Tutorial');
    $this->description = $this->l('A simple module to demonstrate a module development process.');

    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
}

When you are done search for the minicskeleton word, should be there 3 times:

return $this->display(__FILE__, 'views/templates/admin/minicskeleton.tpl');
$this->context->smarty->assign('MinicSkeleton', array(

After this a few little thing is remained. You have to change the names in the .tpl files, to respect the translation standards. Basically you’ll change the content of 2 files, the minictutorial.tpl which was renamed previously, and the home.tpl.

The third file is the quick_link.tpl which is located in the views/templates/hooks/ folder and needed by the dashboard on the backend. In this file you can add a custom icon to show up on the dashboard, a name and a description (this doesn’t show up by default).

Feel free to change everything as you need, the only important thing is to change the minicskeleton to minictutorial.

<li>
  <a href="{$link->getAdminLink('AdminModules')}&configure={$minictutorial}" style="background: url('{$module_dir}logo.png') no-repeat center 25px #F8F8F8">
    <h4>{l s='minic tutorial module' mod='minictutorial'}</h4>
    <p>{l s='A sample module for developers.' mod='minictutorial'}</p>
  </a>
</li>

As you can see i have changed the package_add.png to the module logo, so on the dashboard that will be appear.

Finishing touches

There are a few non-important / important thing, which depends on your goals with this module. These are the license, the logo and the changelog/readme. The module contains the GPLv3 license, the full license text can be found in the license.txt. The module main php file (now minictutorial.php) contains a notice of the license with the copyright holder which is Minic Studio S.R.L. , its strongly recommended to change at least this to your name / company.

The changelog and readme files can be removed if you do not wish to use them. The logo can be changed to yours as well, a 32×32 px PNG and a 16×16 px GIF icon is needed, these appear in the module list and in the module search.

Conclusion

Basically we are done.

You have your own module which at the moment do nothing, you can install / uninstall it but thats all. If you read the tutorials on the Prestashop documentation page you can find your path to make awesome modules in the future.

Our skeleton modules basically do nothing just a little help for those who develop modules frequently and want to speed up things.

I`m planning to continue this tutorial in the future with a simple module which can do “things”, handle multilanguage and multistore.

Finally
I`m open to module ideas, so feel free to add an advice in the comments.

Happy coding!

Share with others!

7

Hozzászólások:

Új komment
  1. avatar
    Rene, ezt írta:

    Very nice idea, thank you.
    It would be nice to have a “how to” for a database manipulation, for instance (very simple) to change the status of orders ticking a list, so changing all “sent” orders to “delivered”.
    With Prestashop you have to do that one by one.
    All the best

    Reply
  2. avatar
    outdoors, ezt írta:

    Yοu shօuld be a part of a contest fߋr one οf thhe most սseful
    sites onn the net. I will recommend thiѕ site!

    Reply
avatar

Leave a comment Saeed

Close