diff --git a/uc_userpoints_product.install b/uc_userpoints_product.install
index 955ac5e..5961111 100644
--- a/uc_userpoints_product.install
+++ b/uc_userpoints_product.install
@@ -7,42 +7,50 @@
  */
 function uc_userpoints_product_schema() {
   $schema['uc_userpoints_products'] = array(
+  'description' => t('TODO: please describe this table!'),
     'fields' => array(
       'upid' => array(
+      'description' => t('TODO: please describe this field!'),
         'type' => 'serial', 
         'not null' => TRUE,
       ),
       'pfid' => array(
+      'description' => t('TODO: please describe this field!'),
         'type' => 'int', 
         'size' => 'medium', 
         'not null' => TRUE, 
         'default' => 0, 
-        'disp-width' => '9',
+    ),
+    'oid' => array(
+      'description' => t('TODO: please describe this field!'),
+      'type' => 'int',
+      'not null' => TRUE,
       ),
       'nid' => array(
+      'description' => t('TODO: please describe this field!'),
         'type' => 'int', 
         'size' => 'medium', 
         'not null' => TRUE, 
         'default' => 0, 
-        'disp-width' => '9',
       ),
       'tid' => array(
+      'description' => t('TODO: please describe this field!'),
         'type' => 'int', 
         'size' => 'medium', 
         'not null' => TRUE, 
         'default' => 0, 
-        'disp-width' => '9',
       ),
       'points' => array(
+      'description' => t('TODO: please describe this field!'),
         'type' => 'int', 
         'size' => 'medium', 
         'not null' => TRUE, 
         'default' => 0, 
-        'disp-width' => '9',
-      )
+    ),
     ),
     'primary key' => array('upid'),
   );
+
   return $schema;
 }
 
diff --git a/uc_userpoints_product.module b/uc_userpoints_product.module
index f26d642..2ab61e4 100644
--- a/uc_userpoints_product.module
+++ b/uc_userpoints_product.module
@@ -62,16 +62,36 @@ function uc_userpoints_product_product_feature() {
 */
 function uc_userpoints_product_feature_form($form_state, $node, $feature) {
 	$points = 0;
-        $tid = NULL;
+  $tid = $oid = NULL;
 
         if($feature) {
 	$res = db_query("SELECT * FROM {uc_userpoints_products} ucup, {uc_product_features} ucpf WHERE ucup.pfid = ucpf.pfid AND ucup.pfid = %d",$feature['pfid']);
 	while ($pf = db_fetch_object($res)) {
 	  $points = $pf->points;
 	  $tid = $pf->tid;
+      $oid = $pf->oid;
 	}
         }
 	
+  if(module_exists('uc_attribute')) {
+    foreach(uc_attribute_load_product_attributes($node->nid) as $attribute) {
+      foreach($attribute->options as $option) {
+        $attr_select[$option->oid] = $attribute->name . ' - ' . $option->name;
+      }
+    }
+    if(!empty($attr_select)) {
+      array_unshift($attr_select, '<any>');
+    }
+  }
+  
+  $form['oid'] = array(
+   '#type' => 'select',
+   '#title' => t('Attribute to operate on'),
+   '#options' => isset($attr_select) ? $attr_select : array(),
+   '#default_value' => $oid,
+   '#access' => isset($attr_select),
+  );
+
 	$category_options = userpoints_get_categories();
 	$category_options[-1] = t('Default '.variable_get(USERPOINTS_TRANS_LCPOINTS, 'Points').' Product Category');
 
@@ -114,12 +134,12 @@ function uc_userpoints_product_feature_form_submit($form, &$form_state) {
 	$term = taxonomy_get_term($form_state['values']['tid']);
 	$data = array(
 		'pfid' => $form_state['values']['pfid'],
+   'oid' => $form_state['values']['oid'],
 		'nid' => $form_state['values']['nid'],
 		'points' => $form_state['values']['points'],
 		'tid' => $form_state['values']['tid'],
 		'fid' => 'userpoints',
 		'description' => t('Product is worth !num_points !category !points', array('!num_points' => $form_state['values']['points'], '!points' => variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'), '!category' => $term_name)),
-
 	);
 
 	$ret = uc_product_feature_save($data);
@@ -127,10 +147,9 @@ function uc_userpoints_product_feature_form_submit($form, &$form_state) {
 	if (!$data['pfid']) {
 	  $data['pfid'] = db_result(db_query("SELECT MAX(pfid) FROM {uc_product_features} WHERE nid = %d AND fid = '%s'", $data['nid'], $data['fid']));
     drupal_write_record('uc_userpoints_products', $data);
-
 	}
 	else {
-		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']);
+    drupal_write_record('uc_userpoints_products', $data, 'pfid');
 	}
 
 	$form_state['redirect'] = $ret;
@@ -144,7 +163,6 @@ function uc_userpoints_product_feature_settings() {
 	// Nothing yet.
 }
 
-
 /**
  * Product Feature delete function
  */
@@ -153,7 +171,6 @@ function uc_userpoints_product_feature_delete($feature) {
 		db_query("DELETE FROM {uc_product_features} WHERE pfid = %d", $feature['pfid']);
 }
 
-
 /**
  * Implementation of hook_order();
  */
@@ -161,8 +178,23 @@ function uc_userpoints_product_order($op, $order, $status) {
   switch($op) {
     case 'update':
       if (($status == 'completed' && $order->uid > 0) && ($order_user = user_load(array('uid' => $order->uid))) !== FALSE) {
+
         foreach($order->products as $product) {
-          $result = db_query("SELECT * FROM {uc_userpoints_products} WHERE nid = %d", $product->nid);
+          $args = array($product->nid);
+
+          $options = array();
+
+          foreach($product->data['attributes'] as $attribute) {
+            $options+= array_keys($attribute);
+          }
+
+          $where_clause = "oid = 0";
+          if(!empty($options)) {
+            $where_clause.= " OR oid IN(" . db_placeholders($options) . ")";
+            $args = array_merge($args, $options);
+          }
+
+          $result = db_query("SELECT * FROM {uc_userpoints_products} WHERE nid = %d AND ($where_clause)", $args);
           while($record = db_fetch_array($result)) {
             $replacements = userpoints_translation() + array('!product' => l($product->title, 'node/' . $product->nid), '!order' => $order->oid);
             $message = t('!Points purchased through !product as part of order !order', $replacements);
@@ -177,6 +209,7 @@ function uc_userpoints_product_order($op, $order, $status) {
             );
             userpoints_userpointsapi($params);
           }
+
         }
       }
   }
