Hi eComLabs!
I think you should should add products.post.php controller for backend and add necessary actions for the update_file mode
Yes! Is what I have in mind. Do you know what function is responsable to generate the ekeys for "files to sell"? The unique function that I found was fn_generate_ekeys_for_edp, but is not very clear to me what information should be passed as variables. I am not sure algo if this is the correct function because is said in the end that is for e-mail notification.
/**
* Generates EDP ekeys for email notification
*
* @param array $statuses order statuses
* @param array $order_info order information
* @param array $active_files array with file download statuses
*
* @return array $edp_data
*/
function fn_generate_ekeys_for_edp(array $statuses, array $order_info, array $active_files = [])
{
/**
* Actions before generating ekeys for downloadable products (EDP)
*
* @param array $statuses Order statuses
* @param array $order_info Order information
* @param array $active_files Array with file download statuses
*/
fn_set_hook('generate_ekeys_for_edp_pre', $statuses, $order_info, $active_files);
$edp_data = array();
$order_statuses = fn_get_statuses(STATUSES_ORDER, [], true);
foreach ($order_info['products'] as $v) {
// Generate ekey if EDP is ordered
if (empty($v['extra']['is_edp']) || !YesNo::toBool($v['extra']['is_edp'])) {
continue;
}
$activations = db_get_hash_single_array('SELECT activation_type, file_id FROM ?:product_files WHERE product_id = ?i AND status = ?s', ['file_id', 'activation_type'], $v['product_id'], ObjectStatuses::ACTIVE);
foreach ($activations as $file_id => $activation_type) {
// Check if ekey already was generated for this file
$_ekey = db_get_row('SELECT ekey, active, file_id, product_id, order_id, ekey FROM ?:product_file_ekeys WHERE file_id = ?i AND order_id = ?i', $file_id, $order_info['order_id']);
if (!empty($_ekey)) {
$_ekey['activation'] = $activation_type;
$paid_statuses = fn_get_settled_order_statuses();
// If order status changed to "Processed"
if (($activation_type === 'P') && !empty($statuses) && !isset($active_files[$v['product_id']][$file_id])) {
if (in_array($statuses['status_to'], $paid_statuses)) {
$active_files[$v['product_id']][$file_id] = YesNo::YES;
} else {
$active_files[$v['product_id']][$file_id] = YesNo::NO;
}
}
if (!empty($active_files[$v['product_id']][$file_id])) {
db_query('UPDATE ?:product_file_ekeys SET ?u WHERE file_id = ?i AND product_id = ?i AND order_id = ?i', ['active' => $active_files[$v['product_id']][$file_id]], $_ekey['file_id'], $_ekey['product_id'], $_ekey['order_id']);
if ($active_files[$v['product_id']][$file_id] === YesNo::YES && $_ekey['active'] !== YesNo::YES) {
$edp_data[$v['product_id']]['files'][$file_id] = $_ekey;
}
}
} else {
$_data = [
'file_id' => $file_id,
'product_id' => $v['product_id'],
'ekey' => md5(uniqid(rand())),
'ttl' => (TIME + (Registry::get('settings.General.edp_key_ttl') * 60 * 60)),
'order_id' => $order_info['order_id'],
'activation' => $activation_type,
];
// Activate the file if type is "Immediately" or "After full payment" and order statuses is from "paid" group
if (
$activation_type === 'I'
|| !empty($active_files[$v['product_id']][$file_id]) && $active_files[$v['product_id']][$file_id] === YesNo::YES
|| ($activation_type === 'P' && !empty($statuses)
&& $order_statuses[$statuses['status_to']]['params']['inventory'] === 'D'
&& substr_count('O', $statuses['status_to']) === 0 && (
$order_statuses[$statuses['status_from']]['params']['inventory'] !== 'D'
|| substr_count('O', $statuses['status_from']) > 0
))
) {
$_data['active'] = YesNo::YES;
$edp_data[$v['product_id']]['files'][$file_id] = $_data;
}
db_query('REPLACE INTO ?:product_file_ekeys ?e', $_data);
}
if (empty($edp_data[$v['product_id']]['files'][$file_id])) {
continue;
}
$edp_data[$v['product_id']]['files'][$file_id]['file_size'] = db_get_field('SELECT file_size FROM ?:product_files WHERE file_id = ?i', $file_id);
$edp_data[$v['product_id']]['files'][$file_id]['file_name'] = db_get_field('SELECT file_name FROM ?:product_file_descriptions WHERE file_id = ?i AND lang_code = ?s', $file_id, CART_LANGUAGE);
$edp_data[$v['product_id']]['files'][$file_id]['url'] = fn_url('orders.get_file?file_id=' . $file_id . '&product_id=' . $v['product_id'] . '&ekey=' . $edp_data[$v['product_id']]['files'][$file_id]['ekey'], SiteArea::STOREFRONT, 'http');
if (!isset($edp_data[$v['product_id']]['url'])) {
$edp_data[$v['product_id']]['url'] = fn_url('orders.downloads?product_id=' . $v['product_id'] . '&ekey=' . $edp_data[$v['product_id']]['files'][$file_id]['ekey'], SiteArea::STOREFRONT, 'http');
}
if (isset($edp_data[$v['product_id']]['product'])) {
continue;
}
$edp_data[$v['product_id']]['product'] = $v['product'];
}
}
/**
* Actions after generating ekeys for downloadable products (EDP)
*
* @param array $statuses Order statuses
* @param array $order_info Order information
* @param array $active_files Array with file download statuses
* @param array $edp_data EDP ekeys for email notification
*/
fn_set_hook('generate_ekeys_for_edp_post', $statuses, $order_info, $active_files, $edp_data);
return $edp_data;
}