Prestashop override: how and why?

Those who have been using Prestashop for a long time know how annoying it was to have to modify the code directly in the core. Fortunately, since version 1.4, it’s now possible to create a Prestashop override. Let’s take a look.

Prestashop override definition

An override is a file that is added to Prestashop and complements or even replaces its native functions. When you create a Prestashop override, it is detected and given priority over the element it overrides. You can therefore make your modifications without having to worry about Prestashop updates.

Usefulness of Prestashop overrides

First of all, you can create overrides for classes, controllers and modules. For the latter, however, you should be aware that your override can only replace the JS, CSS or TPL files of your base module. Why not the PHP files? My answer is that we’re already in a modular architecture, and that overriding a module’s PHP files would be somewhat pointless. Why not override the override too?!

How to create a Prestashop override

Creating an override of Prestashop classes or controllers

I recently needed to create an override of the SpecificPrice class for an agency client. I placed a file named SpecificPrice.php in the “override/classes/” folder and modified the class declaration as follows:

<?php
class SpecificPriceCore extends ObjectModel {
}

becomes

<?php
class SpecificPrice extends SpecificPriceCore {
}

The content of our override will of course depend on the functions you wish to add or modify.

Creating a Prestashop module override

If you wish to modify the TPL, CSS or JS files of a module, simply duplicate these files in your theme as follows. CSS overrides will be placed in “themes/my-theme’s-name/css/my-module/ JS overrides will be placed in “themes/my-theme’s-name/js/my-module/

Conclusion

The use of overriding has become essential since it became possible. As you’ve seen, setting up a surcharge is fairly straightforward, but there are a few limitations. Don’t hesitate to call on professionals who can advise you and take on tasks such as development that are not necessarily part of your skill-set.