=== modified file 'uc_discount.module'
--- uc_discount.module	2009-03-13 14:30:16 +0000
+++ uc_discount.module	2009-04-17 18:08:23 +0000
@@ -52,23 +52,40 @@
   }
 }
 
-function uc_discount_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
-  switch ($op) {
-    case 'load':
-      global $user;
-
-      if (uc_product_is_product($node)) {
-        ca_pull_trigger('calculate_product_discounts', $node, $user);
-      }
-      break;
-  }
-}
-
 /******************************************************************************
  * Ubercart hooks                                                             *
  ******************************************************************************/
 
 /**
+ * Implementation of hook_uc_price_handler().
+ */
+function uc_discount_uc_price_handler() {
+  return array(
+    'alter' => array(
+      'title' => t('Discount price handler'),
+      'description' => t('Adds discounts to product prices.'),
+      'callback' => 'uc_discount_price_handler_alter',
+    ),
+  );
+}
+
+function uc_discount_price_handler_alter(&$price_info, &$context, &$options) {
+  global $user;
+  static $prices;
+  if (isset($context['subject']['node']) && (!isset($context['subject']['field']) || $context['subject']['field'] == 'sell_price')) {
+    $node = $context['subject']['node'];
+    if (!isset($prices[$node->nid])) {
+      ca_pull_trigger('calculate_product_discounts', $node, $user);
+      $prices[$node->nid] = $node->sell_price;
+    }
+    else {
+      $node->sell_price = $prices[$node->nid];
+    }
+    $price_info['price'] = $node->sell_price;
+  }
+}
+
+/**
  * Update and save discount line items to the order.
  */
 function uc_discount_order($op, $arg1, $arg2) {
@@ -110,6 +127,13 @@
       // Delete line items that weren't calculated, update those that have
       // the same titles with the new amounts, and add any that were not there
       // before.
+      $context = array(
+        'revision' => 'formatted',
+        'location' => 'tax-changes-log',
+        'subject' => array(
+          'order' => $arg1,
+        ),
+      );
       if (is_array($arg1->line_items)) {
         foreach ($arg1->line_items as $i => $line) {
           if ($line['type'] == 'discount') {
@@ -119,9 +143,10 @@
               // amounts are not.
               if ($new_line['title'] == $line['title']) {
                 if ($new_line['amount'] != $line['amount']) {
+                  $context['subject']['line_item'] = $new_line;
                   uc_order_update_line_item($line['line_item_id'], $new_line['title'], $new_line['amount']);
                   $arg1->line_items[$i]['amount'] = $new_line['amount'];
-                  $changes[] = t('Changed %title to %amount.', array('%amount' => uc_currency_format($new_line['amount']), '%title' => $new_line['title']));
+                  $changes[] = t('Changed %title to %amount.', array('%amount' => uc_price($new_line['amount'], $context), '%title' => $new_line['title']));
                 }
 
                 // Hide this discount so we don't add or delete it later.
@@ -150,7 +175,8 @@
           uc_order_line_item_add($arg1->order_id, $line['id'], $line['title'], $line['amount'], $line['weight']);
           $line['type'] = 'discount';
           $arg1->line_items[] = $line;
-          $changes[] = t('Added %amount for %title.', array('%amount' => uc_currency_format($line['amount']), '%title' => $line['title']));
+          $context['subject']['line_item'] = $line;
+          $changes[] = t('Added %amount for %title.', array('%amount' => uc_price($line['amount'], $context), '%title' => $line['title']));
         }
       }
 
@@ -642,7 +668,7 @@
   foreach ($predicates as $predicate) {
     if (ca_evaluate_conditions($predicate, $arguments)) {
       $discounts = ca_perform_actions($predicate, $arguments);
-      foreach ($discounts as $i => $discount) {
+      foreach ((array) $discounts as $i => $discount) {
         if ($predicate['#actions'][$i]['#name'] == 'uc_discount_action_get_order_discount' && $discount) {
           // Allow successive discounts to inspect this discount by putting
           // it in the order object.

