I took a look in the code to try to fix the issue where certain discounts are not applied to the cart. Turns out one of the functions (uc_discounts_product_check) is always passed a quantity of 1, and then checks this against the condition... which isn't helpful.

I found that editing uc_discounts_cart_item to actually check for discounts rather than applying a given list worked... but this works per item, not per total items bought, so I had to fudge it a bit. Mind you I'm only using product discounts, I have no idea if this would work to fix any other issues, or indeed it may break other things. But, in the great methodology of "it works for me", here is the code:

--- discounts/uc_discounts_product.module	2008-11-17 07:07:53.000000000 +0000
+++ discounts/uc_discounts_product.module	2009-11-13 15:03:27.000000000 +0000
@@ -38,31 +38,8 @@
  ******************************************************************************/
 
 function uc_discounts_product_check($condition, $total_price, $cart) {
-  $product_count = 0;
-  foreach ($cart as $product) {
-//drupal_set_message(t("checking condition(%c) item_id(%i) against product(%n) %t",array('%c' => $condition->id,'%n' => $product->nid, '%t' => $product->title,'%i' => $condition->item_id)));
-    if ($product->nid == intval($condition->item_id)) {
-      $product_count = $product->qty;
-//drupal_set_message(t("testing condition(!c) item(!i) value(!v) !o product(!n) qty(!q)",array('!c' => $condition->id,
-//                            '!i' => $condition->item_id,
-//                            '!v' => $condition->value,
-//                            '!o' => $condition->op,
-//                            '!n' => $product->nid,
-//                            '!q' => $product_count)));
-      break;
-    }
-  }
-
-  if ($product_count == 0) {
-    return FALSE;
-  }
-  elseif ($condition->op == '=' && $product_count >= $condition->value) { return TRUE; }
-  elseif ($condition->op == '!=' && $product_count != $condition->value) { return TRUE; }
-  elseif ($condition->op == '>=' && $product_count >= $condition->value) { return TRUE; }
-  elseif ($condition->op == '>' && $product_count > $condition->value) { return TRUE; }
-  elseif ($condition->op == '<=' && $product_count <= $condition->value) { return TRUE; }
-  elseif ($condition->op == '<' && $product_count < $condition->value) { return TRUE; }
-  else { return FALSE; }
+  // this is pointless to check here since we are passed a quantity of 1. So, forget it:
+  return false;
 }
 
 function uc_discounts_product_count($condition, $cart) {
--- uc_discounts.module	2008-11-20 15:30:33.000000000 +0000
+++ uc_discounts.module	2009-11-13 14:57:18.000000000 +0000
@@ -304,13 +304,17 @@
   switch ($op) {
     case 'load':
       if (variable_get('uc_discounts_apply_stage', 'order') == 'cart') {
-        $node = node_load($item->nid);
-        $discounts_amount = 0;
-        foreach($node->discounts as $discount) {
-          $discounts_amount += $discount['amount'];
-        }
-        $item->price = $item->price - $discounts_amount;
+      $apply_discounts = uc_discounts_apply_discounts(array($item));
+      if (empty($apply_discounts)) {
+        return;
+      }
+      $discount_total = 0;
+      foreach ($apply_discounts as $discount) {
+        $discount_total = $discount['amount'];
       }
+      $discount = $discount_total / $item->qty;
+      $item->price = $item->price - $discount;
+}
       break;
   }
 }

Comments

selbysaurus’s picture

Hahaha I should check code more thoroughly myself, I've already found more issues.

I'll keep going...

selbysaurus’s picture

OK you need to comment out the static variable and it's check at the start of uc_discounts_apply_discounts for it to work :)

Durrok’s picture

djomp - Can you be more specific about which static variable you are referring to or did you edit your code in your previous post already?