The incorrect discount is being applied to a coupon code when that same code has been used to make previous purchases.

Scenario:

  • Using a coupon of a value of $20 dollars.
  • purchase an item that costs $1
  • complete the purchase if needed in the transaction table
  • repeat these steps one or more times to see the effect

You'll see that the discount value of the coupon never changes from $19, no matter how many times to re-apply the coupon code.

in coupon_checkoutapi the line

        elseif ($coupon = db_fetch_object(db_query("SELECT c.*, tc.txnid, SUM(tc.discount) as coupon_discount FROM {ec_coupon} c LEFT JOIN {ec_transaction_coupon} tc ON c.coupon = tc.coupon WHERE c.coupon = '%s' GROUP BY c.coupon, c.operator, c.operand, c.created, c.created_txnid, c.created_vid, tc.txnid", $new_coupon))) {
          if (($coupon->operator == '%' && $coupon->txnid) || ($coupon->txnid && ($coupon->operand * ($coupon->operator == '+' ? 1 : -1)) <= (float)$coupon->coupon_discount)) {
            form_set_error('new_coupon', $error);
          }

returns multiple rows instead of one row that contains the sum of the discounts used. Removing the GROUP BY clause will solve the issue. Don't see how having the GROUP BY clause is handy in this particular situation.

Comments

number3’s picture

This issue may be in version 5.x-3.5 as well

apaderno’s picture

Version: 5.x-3.4 » 5.x-3.x-dev
Issue summary: View changes
Status: Active » Closed (outdated)
Issue tags: -coupon, -group by, -discount +Discount

I am closing this issue, as Drupal 5 is now not supported.