Hi :)
I have a structure in place, and I'm not sure how to put it into practise.
Let's say I have a shopping cart website where users must register to order.
If a user places an order and completed their purchase on the first day, they get 100 points. If they complete it on the second day, they get 70 points. Third day, 50 points. If eventually they didn't complete the order in 7 days they get no points, possibly negative points.
How can I put this into php? I usually do a cronjob for anything that needs a day-to-day schedule, but this is quite specific. The dates are relative to the date the user placed the order, not just every x hours. Also, to save on resources I wouldn't want to perform these checks on every user, only those who have pending orders.
I thought on different ideas but none are really practical.... Any advice would be much appreciated.
Since you said you want to alert them each day, then a daily job that runs your "daily alerts" might be the way to go. It would simply query on the ones where the order is pending and was started started in the last week, loop over those and send out alerts based on the original start date compared to the current date, and apply the appropriate points at the same time. cronjob that calls a PHP script isn't a bad idea here. Your query could return the number of days elapsed to make the alerting process simpler. To me, this does fall into a day-to-day schedule... just the results are different each day.
Note of caution: if you do alerts, you have to give them a way to opt out of those (unsubscribe), so your alerting process would need to take into account anyone who has opted out and NOT send those any further alerts.
I don't think you need a scheduled job for this. You can just handle the points whenever users complete the order.
Simply take the completion date (so if you do it during ordering, that's the current date), and compare it to the date the order was started.
EDIT Just noticed the daily alerts in the title. You can run a background job using cron or something like it. Cron just triggers your application, which does all the logic, i.e. it queries for outstanding orders from the last week. In that case, scheduled jobs are the right solution.
Kaveh Taher
just a coder experiencing his 30s...
Aaa... Well... I wouldn't say Cronjobs are required for this... just a trigger would take care of it.. well, I'm just a weirdo ..