Foreword

This documentation is for developer and designer, it’s quite technical.

If you’re looking for the User documentation, it’s here: PrestaShop User Documentation

Coding Standards

Consistency is important, even more so when writing open-source code, since the code belongs to millions of eyeballs, and bug-fixing relies on these teeming millions to actually locate bugs and understand how to solve it.

This is why, when writing anything for PrestaShop, be it a theme, a module or a core patch, you should strive to follow the following guidelines. They are the ones that the PrestaShop developers adhere to, and following them is the surest way to have your code be elegantly integrated in PrestaShop.

In short, having code consistency helps keeping the code readable and maintainable.

Starting with version 1.6.1.0, the PrestaShop Core codebase has switched to the PSR-1 coding standard and PSR-2 coding style guide. See the reasons why on the announcement article on the Build PrestaShop deblog.

Existing modules and themes are not required to switch to PSR-1 and PSR-2. PrestaShop’s own modules and any newly-created community module are expected to adopt these guidelines.

If you want to update your PHP code to the PSR-1 and PSR-2 guidelines, you can use the PHP Coding Standards Fixer, which fixes most issues automatically.

For reference’s sake, the old PrestaShop coding standards is kept in this page: Pre-PrestaShop 1.6.1.0 PHP Coding Standards. Please do not use it anymore!

Note

As of May 10th, 2016, our chosen standards were further detailed. Read the announcement article.

Here are the standards, conventions and guidelines that we choose to follow as of May 10th, 2016 (for PrestaShop 1.6.1.5+ and PrestaShop 1.7):

About the code validator (PHP CodeSniffer)

The CodeSniffer configuration file is not yet available. Thank you for your patience!

Contribute

How to request a new hook (with a nice PR)

  • Add hook where you want it in the codebase
  • Declare it in XML

How to name it

Action prefix for hook that do stuff. Display prefix for hook that display stuff. After and Before should be used at the end (ActionProductUpdateBefore instead of ActionBeforeProductUpdate)

What to pass as a param

Think about what you need but think even more about what other people might need.

If you need an order, pass the whole object instead of the only the ID.