Jump to content

How to override ps_imageslider


Recommended Posts

Hi,

I'm trying to override PS module ImageSlider to add a custom field (to be able to change text colour, just a boolean for dark or light, I'll try colour picker later! 😅 )

I added a folder ps_imageslider in override > modules, then a ps_imageslider.php where I did the override of all the functions I was interesting in. As I couldn't manage to just override part of the functions and call parent function I copied-pasted the complete functions:

  • installSamples()
  • createTables()
  • _postProcess()
  • getSlides()
  • renderAddForm()
  • getAddFieldsValues()

This is working (adding a new column to table in database, setting field in configuration page, getting this new value from template, etc.)

 

But when I update the field from the configuration page and click save, nothing is saved. I managed to make it work by modifying the original object model Ps_HomeSlide.php file (adding to it a new property) but I would like to be able to override that file instead of making the change directly in the original module.

Any help will be really appreciated, I can be more specific in the modifications I did if it can help.

Thanks in advance!

Edited by Minsky_ae (see edit history)
Link to comment
Share on other sites

Hope I'm allowed to add external resources on this forum, I found this old StackOverFlow topic talking about almost exactly what I'm trying to achieve : https://stackoverflow.com/questions/40534229/prestashop-override-core-module-class

There is three solutions listed (one is the solution I'm gonna use for now, overriding the original file), but I'm still hoping there is a better way to do this.

Edited by Minsky_ae
Add link (see edit history)
Link to comment
Share on other sites

Well, after testing more thoroughly, it doesn't work :(

If I try to override protected function _postProcess() even without making a change in this function, as soon as I do a copy-paste in the ps_imageslider.php override file, the image upload doesn't work any more. I'm not sure why.

So finally, I did a copy-paste of the module entirely, changing it's name and deleting all the files I didn't think were necessary, so I could install my own version of this module. It's working, for now if ps_imageslider got an update, I'll probably just do a copy-paste again and write my modification in it again.

Definitely not the best way to do it, so if anyone has a better solution, I'm listening :)

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...