? uc_price_handlers_3.patch
Index: uc_discount.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_discount/uc_discount.module,v
retrieving revision 1.4
diff -u -p -r1.4 uc_discount.module
--- uc_discount.module	13 Mar 2009 13:40:26 -0000	1.4
+++ uc_discount.module	11 Apr 2009 21:46:06 -0000
@@ -52,25 +52,40 @@ function uc_discount_form_alter(&$form, 
   }
 }
 
+
+/******************************************************************************
+ * Ubercart hooks                                                             *
+ ******************************************************************************/
+
 /**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_uc_price_handler().
  */
-function uc_discount_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
-  switch ($op) {
-    case 'load':
-      global $user;
+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',
+    ),
+  );
+}
 
-      if (uc_product_is_product($node)) {
-        ca_pull_trigger('calculate_product_discounts', $node, $user);
-      }
-      break;
+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;
   }
 }
 
-/******************************************************************************
- * Ubercart hooks                                                             *
- ******************************************************************************/
-
 /**
  * Update and save discount line items to the order.
  */
@@ -645,7 +660,7 @@ function uc_discount_calculate_discounts
   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.
