PrestaShop development is not easy at all. The software’s architecture requires a few good practices that are often ignored, making bug fixing an even more troublesome process for developers. In this article, we will see which are the ten most common mistakes you can make when developing for PrestaShop, and how to avoid them.
1- You don’t keep PS_DEV_MODE enabled
On your dev sites, always keep development mode. If you don’t know how to, just reach out config/defines.inc.php, locate define(‘_PS_MODE_DEV_’, false) and set it to true. If you need to test out performance, you might want to turn on _PS_DEBUG_PROFILING_ as well
2- Not enough testing
It’s obvious, but again often overlooked. Always make sure you test your modules on all the PrestaShop versions you want it to work with.. Test it not only locally, but online as well. If it involves category pages, make sure it works and it’s compatible with the Layered Navigation module. Also, try to have as many standard modules installed as you can, when you run your tests; this ensures your addon is compatible with at least the basic functionalities of the software.
3- Core files modification
I will never stress this highly enough: do not ever apply your modifications directly to core files (unless it’s impossible to do otherwise). Always use overrides, since it’s easier to point out a modification added with this method, rather than having to scrub through all the original files.
4- Not enough comments
Even if you use overrides, make sure you point out which part of the code you amended. I often found myself lost in overridden methods, since they were an almost identical copy of the original, with the tiniest modification to a single sql query, without anything pointing it out.
5- Breaking the MVC pattern
If you need to query the database, always use a class. It’s bad practice to run queries directly from controllers, so make sure you always use them exclusively to bind a class to a view. You will have to create another file, but the result is going to be cleaner and easier to maintain. For example, if you need you get a list of entries from your module’s table, you might want to have a class included in your controller with require_once at the very beginning of it. Alternatively, you can always access the module’s core file’s methods from any controller, using $this->module.
8- No indentation indentation/formatting
Try to format your code a bit. It’s not necessary to slavishly follow the standards PrestaShop requires to validate a module for the addons store, if you are selling it on your site. However, it’s a lot easier for us other developers to read your code, if it has a decent formatting.
9- Extensive usage of custom code for the back office
PrestaShop has tons of helpers for the back office, it’s better to rely on those instead of writing huge blocks of code with custom styling. It’s always better to output things with a template, whenever possible, and in any case use the standard css classes/boxes even when outputting directly from PHP.
10 – Eccessive use of custom hooks
Plenty templates I worked on had an insane amount of custom hooks. If you are a template developer, try to keep them at a bare minimum, unless strictly necessary, and rely on PrestaShop’s standard ones instead. A theme made up entirely with custom hooks is a real pain to deal with.
Want to know more about PrestaShop Development?
Have a look at my PrestaShop Modules Course