Commission on all items

jgross's picture
Offline
Joined: 08/25/2008
Juice: 11
Commission on all items

I had to edit uc_affiliate_order() in order to get it to work at all. For me, I didn't need the "Find all affiliates related to order" other than those that were upline as affiliates. I changed the function as follows, and is working for me:

<?php
function uc_affiliate_order($op, $order, $status) {
  global
$user;
  if (
$op == 'update' && $status == variable_get('affiliate_commission_order_status', 'completed')) {
   
$total = 0;
    foreach (
$order->products as $product) {
       
$product_total = $product->qty * $product->price;
        
$total = $total + $product_total;
    }
   
$affid = _uc_affiliate_get_user($user->uid);   
    if(
$affid != 0) {
       
// write commission records
       
$affs = _uc_affiliate_get_upline_ids($affid);

        for (

$i=0; $i<count($affs); $i++) {
           
$aff = $affs[$i];
           
$level = $i+1;
           
$comm_pct = _uc_affiliate_get_commission_percentage($level);           
            if (
$comm_pct>0) {
             
//TODO should this be rounded to nearest penny???
             
$comm = $total * $comm_pct;
             
$note = t('Level @level commission of @percent% recorded for affiliate @affiliate', array('@affiliate' => $aff, '@percent' => $comm_pct*100, '@level' => $level, '@commission' => uc_currency_format($comm), '@ordertotal' => uc_currency_format($total), '@firstname' => $order->billing_first_name, '@lastname' => $order->billing_last_name));
             
db_query("INSERT {uc_affiliate_commission} (order_id, aid, commission, commission_notes) VALUES (%d, %d, %f, '%s')", $order->order_id, $aff, $comm, $note);
             
uc_order_comment_save($order->order_id, $user->uid, $note);
             
uc_affiliate_add_count($aff, 0, 0, 1);
            }
        }
     }
  }
}
?>
Affiliate v2 By: mimetic2 (29 replies) Mon, 09/01/2008 - 17:14