I'm developing a module for Prestashop and I'll make a premise valid for Prestashop development environment: a module/plugin can do it's work thanks to some hooks, like Header, or leftBar, or BackOffice header loading, so apparently there is no way to do what I want to do: I want to periodically (let's say each day) check for abandoned cart in Prestashop database and send their information to external API.
I thought of a workaround which I don't like very much and it doesn't seem efficient to me: the plugin installs a custom database that will always contain one row: in that row there will be the current date. Whenever a user visits the website the plugin checks for that value on the DB: if the date is older than today then it updates it to today's date. If the module has just updated the value then I'll do my check on the DB and the API call, else I will not do anything (for the rest of the day, because every other check on the date will fail because it's already updated).
Is there some better way to do it?
********** UPDATE **********
So exists a way: cron tasks. Now my doubt is: is it possible to integrate the cron schedule inside my plugin? I need that when someone installs my plugin then he has nothing more to do: I don't want to delegate the configuration to him through the cron tasks manager integrated on the backoffice of Prestahsop. The problem with Prestashop seems to be that unlike Wordpress where exists a unique solution to do this (https://www.smashingmagazine.com/2013/10/schedule-events-using-wordpress-cron/), there is no way to do that for a general website target, so if you want to do that inside your custom module you have to choose one cron (https://www.prestashop.com/forums/topic/564504-how-create-cron-job-from-custom-module-all-by-code/)
In my opinion the best way to do that is to use a cron or webcron.
You create a front controller on your module that do the work and you create a cron that execute the controller once a day.
How to create a front controller : http://doc.prestashop.com/display/PS16/Displaying+content+on+the+front+office#Displayingcontentonthefrontoffice-Embeddingatemplateinthetheme
if you call your controller cron, you can call it
by shell for crontab :
You can also use a cron-like system based on user visits but I will not recommend this solution if :
There is no built-in solution, there are modules for that but it will not solve your issue, the customer will have to install them.
my solution is to hook on the footer
and in your cron controller