Jump to content

Recommended way to modify method behaviour without using overrides?


psbruce

Recommended Posts

I am fairly new to Prestashop.

 

I want to build a module that makes some small changes to 2 methods in the CountryCore class in Country.php to provide for a more sophisticated post code validation. I also want to change 2 methods in the file js/validate.js to achieve this goal. I have made the changes within the core modules on a test installation and they work perfectly. However, I now want to make this into a module that can be made available to others who experience the same problem.

 

Although there is a lot of information about the wonderful and easy to use override system in Prestashop, which is all understandable, I also keep reading the following statement:

 

 

Keep overrides for your own shop

Overrides in PrestaShop are exclusive. This means that if your module overrides one of PrestaShop's behaviors, another module will not be able to use that behavior properly, or override it in an predictable way.

Therefore, overrides should only be used for your own local modules, when you have a specific need that cannot be applied without it.

It is not recommended to use an override in a module that you intend to distribute (for instance through the PrestaShop Addons marketplace), and they are forbidden in partner modules.

 

 

 

If making use of the override functionality of Prestashop is not the recommended way to make changes to Prestashop core class methods and cannot be included in modules that are intended for distribution, how should such changes be made?

 

What is the recommended way to modify how certain methods work so that their functionality can be extended in a distributable module?

Link to comment
Share on other sites

PrestaShop wants developers to use module hooks instead of overrides. They should ask for new hooks to be added where needed and wait for PrestaShop to add them. I don't think that's going to help you much.

 

Using overrides is the only way to do what you want to do. I have three modules that each have a single override and PrestaShop Addons accepted them. I'm not a partner though. As long as you minimise use of overrides as much as possible, you should be fine.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...