Hello! Created functions for generating, receiving, updating, etc. discount cards. Initially there is an array with 12 encoded data. The encoded data contains an id and a lifetime that is set by adding 1 hour to the current one. I want to perform a function that updates the discount card code when the user is sitting in the session. If the function execution loop is not sitting, it stops when the authorization starts. Tell me how to implement this? Or would it be better to use Cron to perform this function?
Hi!
You can either trigger your function each time the installation scripts are executed, for example, on the before_dispatch
hook, or you can use cron if you have access to it.
Hi! I tried it through cron, it seems to work, but there are a lot of users and when we run cron every hour, it requires a lot of server resources. Can you suggest a method for checking users, not all at once, but several at a time? To optimize.
I’m afraid I don’t understand the details of what you’re doing and what you’re trying to achieve, so I don’t know what to suggest in this case.
Hello. We solved the problem by optimizing the code and functionality logic. It works quickly through Cron. Thank you!
Hello! I wrote it like this. But will updating barcode_ids work?
function fn_loyal_discount_init_user_session_data($sess_data, $user_id, $skip_cart_saving){
$external_id = $sess_data['cart']['user_data']['external_id'];
$user_type = $sess_data['auth']['user_type'];
if(!empty($sess_data) && $user_type == 'C' && !empty($external_id)) {
$barcode_ids = fn_get_discount_barcode_id($user_id, $external_id, $user_type);
if(empty($barcode_ids)) {
$barcode_ids = fn_generate_discount_barcode_id($user_id, $external_id, $user_type);
} else {
$barcode_ids = fn_update_expired_barcodes($user_id, $external_id, $barcode_ids);
}
$sess_data['loyal_barcodes'] = $barcode_ids;
}
}
Sorry, but I don’t know