? userpoints_ubercart-595890.patch
Index: uc_userpoints_product.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_product.install,v
retrieving revision 1.3.4.1
diff -u -p -r1.3.4.1 uc_userpoints_product.install
--- uc_userpoints_product.install	14 May 2009 02:47:13 -0000	1.3.4.1
+++ uc_userpoints_product.install	5 Oct 2009 07:38:52 -0000
@@ -6,6 +6,7 @@ function uc_userpoints_product_schema() 
          'upid' => array('type' => 'serial', 'not null' => TRUE),
          'pfid' => array('type' => 'int', 'size' => 'medium', 'not null' => TRUE, 'default' => 0, 'disp-width' => '9'),
          'nid' => array('type' => 'int', 'size' => 'medium', 'not null' => TRUE, 'default' => 0, 'disp-width' => '9'),
+         'tid' => array('type' => 'int', 'size' => 'medium', 'not null' => TRUE, 'default' => 0, 'disp-width' => '9'),
          'points' => array('type' => 'int', 'size' => 'medium', 'not null' => TRUE, 'default' => 0, 'disp-width' => '9')),
     'primary key' => array('upid'),
   );
Index: uc_userpoints_product.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_ubercart/uc_userpoints_product.module,v
retrieving revision 1.5.2.2
diff -u -p -r1.5.2.2 uc_userpoints_product.module
--- uc_userpoints_product.module	14 May 2009 04:18:27 -0000	1.5.2.2
+++ uc_userpoints_product.module	5 Oct 2009 07:38:52 -0000
@@ -39,7 +39,7 @@ function uc_userpoints_product_userpoint
 			'#title' => t('Product Category'),
 			'#default_value' => variable_get(USERPOINTS_PRODUCT_CATEGORY, NULL),
 			'#options' => userpoints_get_categories(),
-			'#description' => t('Category to assign awarded !points.', userpoints_translation()),
+			'#description' => t('Category to assign awarded !points. This can be overridden on a per product basis', userpoints_translation()),
 	      );
 		}
 		return $form;
@@ -70,11 +70,12 @@ function uc_userpoints_product_feature_f
 	$res = db_query("SELECT * FROM {uc_userpoints_products} ucup, {uc_product_features} ucpf WHERE ucup.pfid = ucpf.pfid AND ucup.nid = %d",$nid);
 	while ($pf = db_fetch_object($res)) {
 	  $points = $pf->points;
+	  $tid = $pf->tid;
 	}
 
 	$form['nid'] = array(
 		'#type' => 'value',
-		'#value' => $node->nid,
+		'#value' => $nid,
 	);
 	$form['points'] = array(
 		'#type' => 'textfield',
@@ -82,6 +83,14 @@ function uc_userpoints_product_feature_f
 		'#description' => t('How many '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').' to give when this product is purchased.'),
 		'#default_value' => $points,
 	);
+	$form['tid'] = array(
+		'#type' => 'select',
+		'#title' => t('Product Category'),
+		'#default_value' => $tid,
+		'#options' => userpoints_get_categories(),
+		'#description' => t('Category to assign awarded !points.', userpoints_translation()),
+	 );
+
 	return uc_product_feature_form($form);
 }
 
@@ -101,19 +110,20 @@ function uc_userpoints_product_feature_f
 		'pfid' => $form_state['values']['pfid'],
 		'nid' => $form_state['values']['nid'],
 		'points' => $form_state['values']['points'],
+		'tid' => $form_state['values']['tid'],
 		'fid' => 'userpoints',
 		'description' => 'Product is now worth '.$form_state['values']['points'].' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'),
 	);
 	
 	$ret = uc_product_feature_save($data);
 	if (empty($data['pfid'])) {
-		$pf = db_fetch_object(db_query("select pfid from {uc_userpoints_products} where nid = %d and fid = %d",$data['nid'],$data['fid']));
+		$pf = db_fetch_object(db_query("select pfid from {uc_product_features} where nid = %d and fid = %d",$data['nid'],$data['fid']));
 		$data['pfid'] = $pf->pfid;
 
-		db_query("INSERT INTO {uc_userpoints_products} (pfid,nid,points) VALUES (%d,%d,%d)",$data['pfid'],$data['nid'],$data['points']);
+		db_query("INSERT INTO {uc_userpoints_products} (pfid,nid,points,tid) VALUES (%d,%d,%d,%d)",$data['pfid'],$data['nid'],$data['points'],$data['tid']);
 	}
 	else {
-		db_query("UPDATE {uc_userpoints_products} SET points = %d WHERE nid = %d AND pfid = %d",$data['points'],$data['nid'],$data['pfid']);
+		db_query("UPDATE {uc_userpoints_products} SET points = %d, tid= %d WHERE nid = %d AND pfid = %d",$data['points'],$data['tid'],$data['nid'],$data['pfid']);
 	}
 
 	$form_state['redirect'] = $ret;
@@ -149,26 +159,31 @@ function uc_userpoints_product_order($op
 				$totalPoints = 0;
 				foreach ($order->products as $product) {
 					$points = db_result(db_query("SELECT sum(points) FROM {uc_userpoints_products} WHERE nid = %d", $product->nid));
+					$tid = db_result(db_query("SELECT tid FROM {uc_userpoints_products} WHERE nid = %d", $product->nid));
 					if ($points > 0) {
 						//drupal_set_message($product->title.' has '.$points.' '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'points').' attached');
 						$totalPoints += ($product->qty * $points); // Make sure we account for multiple qty of the Points product
 					}
-				}
-
-			$params = array (
-				'tid' => variable_get(USERPOINTS_PRODUCT_CATEGORY, 0),
-				'uid' => $order->uid,
-				'points' => $totalPoints,
-				'operation' => 'add',
-				'description' => t('A user purchased a product containing points for a total of ' .$totalPoints.' '. variable_get(USERPOINTS_TRANS_LCPOINTS, 'points')),
-				'entity_id' => $order->oid,
-				'entity_type' => 'Ubercart Transaction',
-				'moderate' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
-			);
+					if ($tid != '') {
+			            $tid = variable_get(USERPOINTS_PRODUCT_CATEGORY, 0);
+			        }
+			    
+			    $params = array (
+				    'tid' => $tid,
+				    'uid' => $order->uid,
+				    'points' => $totalPoints,
+				    'operation' => 'add',
+				    'description' => t('A user purchased a product containing points for a total of ' .$totalPoints.' '. variable_get(USERPOINTS_TRANS_LCPOINTS, 'points')),
+				    'entity_id' => $order->oid,
+				    'entity_type' => 'Ubercart Transaction',
+				    'moderate' => variable_get(USERPOINTS_PRODUCT_MODERATE, 0),
+			    );
 
-		 userpoints_userpointsapi($params);
-		 uc_order_comment_save($order->order_id, 0, t('User earned '.$totalPoints.' points!'), 'admin');
-		}
+		        userpoints_userpointsapi($params);
+		        uc_order_comment_save($order->order_id, 0, t('User earned '.$totalPoints.' points!'), 'admin');
+				}
+		    }
+		    
 	break;
 	}
 }
