Drupal: Send file download link & Product key in ubercart confirmation email

This CodeLet will fetch and attach File download link & Product key for software prodcuts on a Durpal ubercart store. You will need to call respective function from the order confirmation template.

CodeLet: 


/**
* @file
*
* Add file download link in order confirmation email.
*
* @author DrupalD
*/

/**
* _get_download_link
*
* Retrive the file download link
*
* @param $sn__order_id
* @author DrupalD
*/
function _get_download_link($sn__order_id, $sn__user_id) {
sleep(10); //Wait till all the other hooks are executed!
$r__result = db_query("SELECT uf.filename, uf.fid, ufu.file_key FROM {uc_files} uf
LEFT JOIN {uc_file_users} ufu ON uf.fid = ufu.fid LEFT JOIN
{uc_product_features} upf ON ufu.pfid = upf.pfid LEFT JOIN
{uc_order_products} uop ON upf.nid = uop.nid LEFT JOIN
{uc_orders} uo ON uop.order_id= uo.order_id
WHERE uo.uid = %d AND uo.order_id = %d
AND ufu.uid = %d AND uo.order_status = 'completed'", $sn__user_id, $sn__order_id, $sn__user_id);

$om__download = db_fetch_object($r__result);
//You have to setup the menu if not already set up
return "/download/". $om__download->fid .'/'. $om__download->file_key ."'>". $om__download->filename ."";
}

/**
* _get_product_key
*
* @param $sn__order_id
* @author DrupalD
*/
function _get_product_key($sn__order_id) {
return db_result(db_query("SELECT product_key FROM {uc_product_keys} upk WHERE order_id = %d", $sn__order_id));
}

By DrupalD on Fri, 03/05/2013 - 11:00am

Add comment

Log in or register to post comments
QR code for this page URL This page URL
Feedback