function uc_file_order in Ubercart 5
Implementation of hook_order().
File
- uc_file/
uc_file.module, line 199 - Allows products to be associated with downloadable files.
Code
function uc_file_order($op, $order, $status) {
global $user;
switch ($op) {
case 'update':
// Only process file downloads when the order is being updated to the
// correct status, the status is actually being changed, and a valid user
// has been assigned to the order.
if ($status == variable_get('uc_file_default_order_status', 'completed') && $order->order_status != $status && $order->uid > 0 && ($order_user = user_load(array(
'uid' => $order->uid,
))) !== FALSE) {
foreach ($order->products as $product) {
$files = db_query("SELECT fp.fid, fp.pfid, model, f.filename FROM {uc_file_products} AS fp INNER JOIN {uc_product_features} AS pf ON pf.pfid = fp.pfid INNER JOIN {uc_files} as f ON f.fid = fp.fid WHERE nid = %d", $product->nid);
while ($file = db_fetch_object($files)) {
if ($file->model == $product->model || empty($file->model)) {
$downloads = _user_table_action('allow', $file->fid, $order_user->uid, $file->pfid);
$user_downloads = !empty($user_downloads) ? array_merge($user_downloads, $downloads) : $downloads;
if (_get_dir_file_ids($file->fid)) {
$comment = t('User can now download files in the directory %dir.', array(
'%dir' => $file->filename,
));
}
else {
$comment = t('User can now download the file %file.', array(
'%file' => basename($file->filename),
));
}
uc_order_comment_save($order->order_id, $user->uid, $comment);
}
}
}
if (!is_null($user_downloads)) {
_email_file_download($order_user, $order, $user_downloads);
}
}
break;
default:
break;
}
}