? asd.patch
? epatch.patch
? fancy_discounts.patch
? patch-uc_discounts_product_classes.txt
? phpstuff.patch
? svn.diff
? svn2.diff
? codeless_discounts_field/.svn
? codeless_discounts_field/translations/.svn
? product_price_alterer_field/.svn
? product_price_alterer_field/translations/.svn
? uc_discounts/.cvsignore
? uc_discounts/translations/.cvsignore
Index: uc_discounts/uc_discounts.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_discounts_alt/uc_discounts/uc_discounts.admin.inc,v
retrieving revision 1.10.2.5
diff -u -p -r1.10.2.5 uc_discounts.admin.inc
--- uc_discounts/uc_discounts.admin.inc	8 Jan 2010 17:00:21 -0000	1.10.2.5
+++ uc_discounts/uc_discounts.admin.inc	26 Apr 2010 21:41:51 -0000
@@ -525,6 +525,27 @@ function uc_discounts_form($form_state, 
     "#required" => TRUE,
   );
 
+  $form['discount_set']['per_product'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => FALSE,
+    '#title' => t('Per-product settings'),
+  );
+  $form['discount_set']['per_product']['min_qty'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Minimum quantity of applicable product to receive discount'),
+    '#description' => t('When specified, a per-product discount only applies to individual products that have more than this quantity in the cart.'),
+    '#default_value' => $form_state['values']['min_qty'],
+    '#size' => 7,
+    '#required' => FALSE,
+  );
+  $form['discount_set']['per_product']['round'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Round to nearest even number.'),
+    '#description' => t('When checked, and the product quantity > 0 but odd, the qualifying amount for the discount will use the next lowest even number. For example: 3 products would be treated as 2, but 4 products would be treated as 4.'),
+    '#default_value' => $form_state['values']['round'],
+    '#size' => 7,
+    '#required' => FALSE,
+  );
   $form["discount_set"]["max_uses_per_user"] = array(
     "#type" => "textfield",
     "#title" => t("Max uses per user"),
@@ -793,9 +814,10 @@ function uc_discounts_form_submit($form,
         $form_state["values"]["has_expiration"],
         $expiration,
         $form_state["values"]["is_published"],
-        $form_state["values"]["weight"]
+        $form_state["values"]["weight"],
+        $form_state['values']['min_qty'],
+        $form_state['values']['round']
       );
-
       //Delete existing database codes
       uc_discounts_codes_delete($discount_id);
 
Index: uc_discounts/uc_discounts.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_discounts_alt/uc_discounts/uc_discounts.install,v
retrieving revision 1.9.2.1
diff -u -p -r1.9.2.1 uc_discounts.install
--- uc_discounts/uc_discounts.install	5 Oct 2009 00:58:21 -0000	1.9.2.1
+++ uc_discounts/uc_discounts.install	26 Apr 2010 21:41:51 -0000
@@ -164,6 +164,19 @@ function uc_discounts_schema() {
         "default" => 0,
         "description" => t("The insert date and time as a unix timestamp."),
       ),
+      'min_qty' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => 'The minimum quantiy of a single product to which this discount applies',
+      ),
+      'round' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => 'The minimum quantiy of a single product to which this discount applies',
+      ),
     ),
     "primary key" => array("discount_id"),
   );
@@ -554,3 +567,16 @@ function uc_discounts_update_6() {
   return $queries;
 }
 
+function uc_discounts_update_7() {
+  $ret = array();
+  $field = array(
+    'type' => 'int',
+    'not null' => TRUE,
+    'default' => 0,
+  );
+
+  db_add_field($ret, 'uc_discounts', 'min_qty', $field);
+  $field['size'] = 'tiny';
+  db_add_field($ret, 'uc_discounts', 'round', $field);
+  return $ret;
+}
\ No newline at end of file
Index: uc_discounts/uc_discounts.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_discounts_alt/uc_discounts/uc_discounts.module,v
retrieving revision 1.29.2.8
diff -u -p -r1.29.2.8 uc_discounts.module
--- uc_discounts/uc_discounts.module	26 Nov 2009 17:21:45 -0000	1.29.2.8
+++ uc_discounts/uc_discounts.module	26 Apr 2010 21:41:52 -0000
@@ -571,7 +571,7 @@ function get_uc_discounts_column_names()
     "discount_amount", "requires_code", "filter_type", "has_role_filter",
     "requires_single_product_to_qualify", "required_product", "max_times_applied", "can_be_combined_with_other_discounts", "max_uses",
     "max_uses_per_user", "max_uses_per_code", "has_expiration", "expiration",
-    "is_published", "weight",
+    "is_published", "weight", "min_qty", "round",
   );
 }
 
@@ -598,7 +598,7 @@ function get_uc_discounts_column_printf_
     "%f", "%d", "%d", "%d",
     "%d", "'%s'", "%d", "%d", "%d",
     "%d", "%d", "%d", "%d",
-    "%d", "%d",
+    "%d", "%d", "%d", "%d",
   );
 }
 
@@ -645,6 +645,7 @@ function uc_discounts_insert($name, $sho
   return $discount_id;
 }
 
+
 /**
  * Updates a uc_discounts row.
  */
@@ -654,9 +655,8 @@ function uc_discounts_update($discount_i
   $discount_amount, $requires_code, $filter_type, $has_role_filter,
   $requires_single_product_to_qualify, $required_product, $max_times_applied, $can_be_combined_with_other_discounts, $max_uses,
   $max_uses_per_user, $max_uses_per_code, $has_expiration, $expiration,
-  $is_published, $weight
+  $is_published, $weight, $min_qty, $round
 ) {
-
   $query = "UPDATE {uc_discounts} SET ";
 
   $column_names = get_uc_discounts_update_column_names();
@@ -678,7 +678,7 @@ function uc_discounts_update($discount_i
     $discount_amount, $requires_code, $filter_type, $has_role_filter,
     $requires_single_product_to_qualify, $required_product, $max_times_applied, $can_be_combined_with_other_discounts, $max_uses,
     $max_uses_per_user, $max_uses_per_code, $has_expiration, $expiration,
-    $is_published, $weight, $discount_id
+    $is_published, $weight, $min_qty, $round, $discount_id 
   );
 }
 
@@ -1392,8 +1392,13 @@ function get_discounts_for_order($order,
         $order_and_discount_product_ids = array_intersect($discount_product_ids, $order_product_ids);
         foreach ($order->products as $this_product) {
           if (in_array($this_product->nid, $order_and_discount_product_ids)) {
-            $this_product_price = $this_product->price;
-            $product_sum = $product_sum + $this_product_price;
+            if ($this_product->qty > $discount->min_qty) {
+              $working_qty = $this_product->qty;
+              if ($discount->round && ($odd = $this_product->qty%2)) {
+                $working_qty = $this_product->qty - 1;
+              }
+              $product_sum = $product_sum + ($this_product->price * $working_qty);
+            }
           }
         }
         $discount->amount = $product_sum * $discount->discount_amount;
