--- uc_discount.module	2010-11-20 07:40:08.000000000 +0100
+++ uc_discount.module	2011-02-09 15:15:19.136546001 +0100
@@ -113,7 +113,27 @@ function uc_discount_uc_price_handler()
 function uc_discount_price_handler_alter(&$price_info, &$context, &$options) {
   global $user;
   static $prices = array();
-
+  // http://drupal.org/node/1015054
+ 
+  if($context['subject']['order']->uid)  { 
+        if($context['subject']['order']->uid != $user->uid)  {
+	    $account = user_load($context['subject']['order']->uid); // somebody is watching somebody else's order
+	  }
+	  else  {
+ 	    $account = user_load($user->uid);
+ 	  }
+   } 
+   else { // no  order yet
+       if($context['account']->uid != $user->uid) {
+         $account = user_load($context['account']->uid);
+       }
+      else  {
+        $account = user_load($user->uid);
+      }
+   }
+ 
+  
+  
   switch ($context['type']) {
     case 'product':
       if (isset($context['field']) && $context['field'] != 'sell_price') {
@@ -124,10 +144,12 @@ function uc_discount_price_handler_alter
       $cache = 'node:'. $node->nid .':'. $price_info['price'];
       break;
     case 'cart_item':
-      $node = clone $context['subject']['node'];
-      $item = $context['subject']['cart_item'];
-      $cache = 'cart_item:'. $node->nid .':'. $price_info['price'] .':'. serialize($item->data);
-      break;
+           if (isset($context['subject']['node']) && is_object($context['subject']['node'])){
+                  $node = clone $context['subject']['node'];
+                  $item = $context['subject']['cart_item'];
+                  $cache = 'cart_item:'. $node->nid .':'. $price_info['price'] .':'. serialize($item->data);
+           }
+        break;
     case 'order_product':
       if (isset($context['subject']['node'])){
         $node = clone $context['subject']['node'];
@@ -147,7 +169,7 @@ function uc_discount_price_handler_alter
   if (!isset($prices[$cache])) {
     // The discount action modifies the node's sell_price field.
     $node->sell_price = $price_info['price'];
-    ca_pull_trigger('calculate_product_discounts', $node, $user);
+    ca_pull_trigger('calculate_product_discounts', $node, $account);
     $prices[$cache] = $node->sell_price;
   }
   else {
