### Eclipse Workspace Patch 1.0 #P Drupal Modules 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 diff -u -r1.9 uc_discounts.install --- uc_discounts/uc_discounts.install 22 Aug 2009 21:30:39 -0000 1.9 +++ uc_discounts/uc_discounts.install 26 Apr 2010 22:35:51 -0000 @@ -39,9 +39,8 @@ "default" => 0, ), "qualifying_amount" => array( - "type" => "float", - "not null" => TRUE, - "default" => 0.0, + "type" => "text", + "serialize" => TRUE, "description" => t("Minimum quantity or price required to qualify for this discount."), ), "has_qualifying_amount_max" => array( @@ -63,9 +62,8 @@ "default" => 0, ), "discount_amount" => array( - "type" => "float", - "not null" => TRUE, - "default" => 0.0, + "type" => "text", + "serialize" => TRUE, "description" => t("Amount to discount (i.e. 1 free item, 25%, or $2.00)"), ), "requires_code" => array( @@ -487,3 +485,10 @@ return $queries; } +function uc_discounts_update_5() { + $ret = array(); + $ret[] = update_sql("ALTER TABLE {uc_discounts} CHANGE qualifying_amount qualifying_amount TEXT NULL DEFAULT NULL"); + $ret[] = update_sql("ALTER TABLE {uc_discounts} CHANGE discount_amount discount_amount TEXT NULL DEFAULT NULL"); + return $ret; +} + 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.30 diff -u -r1.30 uc_discounts.module --- uc_discounts/uc_discounts.module 23 Dec 2009 15:27:20 -0000 1.30 +++ uc_discounts/uc_discounts.module 26 Apr 2010 22:35:52 -0000 @@ -579,9 +579,9 @@ */ function get_uc_discounts_column_printf_wildcards() { return array("'%s'", "'%s'", "'%s'", "%d", - "%f", "%d", "%f", "%d", - "%f", "%d", "%d", "%d", - "%d", "%d", "%d", "%d", + "'%s'", "%d", "%f", "%d", + "'%s'", "%d", "%d", "%d", + "%d", "'%s'", "%d", "%d", "%d", "%d", "%d", "%d", "%d", "%d", "%d", ); @@ -1198,14 +1198,15 @@ break; } } - + $discount->qualifying_amount = unserialize($discount->qualifying_amount); + $discount->discount_amount = unserialize($discount->discount_amount); //If order does not qualify for this discount - if ($order_qualifying_amount < $discount->qualifying_amount) { + if ($order_qualifying_amount < $discount->qualifying_amount[0]) { //If this is a coded discount, add warning message if (!is_null($warnings) && !is_null($discount->code)) { switch ($discount->qualifying_type) { case QUALIFYING_TYPE_MINIMUM_PRICE: - $qualifying_amount = uc_currency_format($discount->qualifying_amount); + $qualifying_amount = uc_currency_format($discount->qualifying_amount[0]); $warnings[] = t('The discount for code "@code" requires a minimum price of @qualifying_amount to qualify.', array("@code" => $discount->code, "@qualifying_amount" => $qualifying_amount) ); @@ -1213,13 +1214,21 @@ case QUALIFYING_TYPE_MINIMUM_QUANTITY: $warnings[] = t('The discount for code "@code" requires a minimum quantity of @qualifying_amount to qualify.', - array("@code" => $discount->code, "@qualifying_amount" => $discount->qualifying_amount) + array("@code" => $discount->code, "@qualifying_amount" => $discount->qualifying_amount[0]) ); break; } } continue; } + else { + for ($i = 0; $i < count($discount->qualifying_amount); $i) { + if ($order_qualifying_amount < $discount->qualifying_amount[$i]) { + break; + } + $discount->qualifying_tier = $i; + } + } //If this discount has a maximum qualifying amount and the order exceeds it if ($discount->has_qualifying_amount_max && ($order_qualifying_amount > $discount->qualifying_amount_max)) { @@ -1244,8 +1253,8 @@ } //Determine number of times to apply discount - if ($discount->qualifying_amount != 0) { - $discount->times_applied = (int)($order_qualifying_amount / $discount->qualifying_amount); + if ($discount->qualifying_amount[$discount->qualifying_tier] != 0) { + $discount->times_applied = (int)($order_qualifying_amount / $discount->qualifying_amount[$discount->qualifying_tier]); } else $discount->times_applied = 1; if ($discount->max_times_applied != 0) { @@ -1273,7 +1282,7 @@ $this_product_price = $this_product->price; $product_sum = $product_sum + ($order_product_id_quantity_map[$this_product->nid] * $this_product->price); } - $discount->amount = $product_sum - ($product_sum * $discount->discount_amount); + $discount->amount = $product_sum - ($product_sum * $discount->discount_amount[$discount->qualifying_tier]); } break; case DISCOUNT_TYPE_FREE_ITEMS: @@ -1281,7 +1290,7 @@ $discount_amount = 0; //The variable free_items_remaining is the [max] number of free items for the order - $free_items_remaining = $discount->discount_amount * $discount->times_applied; + $free_items_remaining = $discount->discount_amount[$discount->qualifying_tier] * $discount->times_applied; //Loop until all free items have been applied or there are no more products to //discount (discount cheapest first) @@ -1369,8 +1378,8 @@ if ($are_equal) { //($last_discount->amount / $last_discount->discount_amount) == last discount's subtotal - $local_order_subtotal = ($last_discount->amount / $last_discount->discount_amount); - $discount->amount = $local_order_subtotal * $discount->discount_amount; + $local_order_subtotal = ($last_discount->amount / $last_discount->discount_amount[$last_discount->qualifying_tier]); + $discount->amount = $local_order_subtotal * $discount->discount_amount[$discount->qualifying_tier]; break; } } @@ -1389,23 +1398,23 @@ foreach ($order_and_discount_products as $product) { $discounted_products_amount += $product->price * $product->qty; } - $discount->amount = $discounted_products_amount * $discount->discount_amount; + $discount->amount = $discounted_products_amount * $discount->discount_amount[$discount->qualifying_tier]; // Discount the subtotal so far } else { - $discount->amount = max($order_subtotal - $total_discount_amount, 0) * $discount->discount_amount; + $discount->amount = max($order_subtotal - $total_discount_amount, 0) * $discount->discount_amount[$discount->qualifying_tier]; } //End patch from lutegrass break; case DISCOUNT_TYPE_FIXED_AMOUNT_OFF: - $discount->amount = $discount->discount_amount * $discount->times_applied; + $discount->amount = $discount->discount_amount[$discount->qualifying_tier] * $discount->times_applied; break; case DISCOUNT_TYPE_FIXED_AMOUNT_OFF_PER_QUALIFYING_ITEM: //Discount is the total quantity of qualifying items in order (order_qualifying_amount) //times the discount amount - $discount->amount = $discount->discount_amount * $order_qualifying_amount; + $discount->amount = $discount->discount_amount[$discount->qualifying_tier] * $order_qualifying_amount; break; }