Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple GC purchased not recorded if GVs aren't queued #1457

Closed
lat9 opened this issue Jul 5, 2017 · 1 comment
Closed

Multiple GC purchased not recorded if GVs aren't queued #1457

lat9 opened this issue Jul 5, 2017 · 1 comment

Comments

@lat9
Copy link
Contributor

lat9 commented Jul 5, 2017

ZC1.5.5e. Configure the GC order-total so that GCs aren't queued (not, IMO, a good idea ... but).

Using the demo data, a customer has an existing GC balance of $10.00 and purchases 2 x $5.00 cards and 1 x $10.00 GC in a single order. Upon order-completion, the customer's account reflects a GC balance of $20.00 instead of $30.00.

The issue lies in /includes/modules/order_total/ot_gv.php's user_has_gv_account function:

  function user_has_gv_account($c_id) {
    global $db;
    $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$c_id . "'");
    if ($gv_result->RecordCount() > 0) {
      return $gv_result->fields['amount'];
    }
    return 0; // use 0 because 'false' was preventing checkout_payment from continuing
  }

Since there are multiple GCs in the order, the function is called multiple times to determine the customer's GC balance. Unfortunately, the database cache "remembers" only the first value (10.00); that's why the full GC purchase isn't applied.

To correct for the ZC1.5.5 series:

  function user_has_gv_account($c_id) {
    global $db;
    $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$c_id . "'", false, false, 0, true);
    if ($gv_result->RecordCount() > 0) {
      return $gv_result->fields['amount'];
    }
    return 0; // use 0 because 'false' was preventing checkout_payment from continuing
  }

For the ZC1.6.0 series, replace the $db->Execute function with $db->ExecuteNoCache.

@drbyte
Copy link
Member

drbyte commented Jul 5, 2017

We'd accept a PR for each of the 2 branches with these changes.

@drbyte drbyte closed this as completed in c371520 Aug 15, 2017
drbyte added a commit that referenced this issue Aug 15, 2017
drbyte pushed a commit that referenced this issue Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants