I’m building a Video module that associates an URL with a title (it’s as simple as it gets), but I need it to enforce a “default” behavior in which only one item may be active at any given time. Prestashop’s miserable documentation will be the death of me…
The code for this mini-endeavor can be found here (on another SO question I was struggling with).
My idea was to run an SQL query in the postProcess function inside the AdminVideo controller for the backoffice. Here – and after the insertion/update – I would fire an SQL query that would set the value of the “active” column on all the other rows to 0.
My problem is that this function – postProcess() – gets called again and again (including when the videos need to be listed) and the query can’t run everytime.
I’ve been struggling with this issue for the whole day and don’t know what to do next.
What am I doing wrong?
Is there another method I can overload in order to easily fire an SQL query everytime a row is updated/created?
Are there any decent books on this subject for version 1.5? It’s really frustrating to spend more time looking for answers in SO that doing some actual work.
Thanks, I really appreciate it
You have to check for the submit button in your _postProcess function.
For example, have a look at the _postProcess function of the bankwire module, in the
modules/bankwire/bankwire.phpscript: