I ran some tests a few months back and found that I was able to add a new batch of coupon codes to an existing bulk generated coupon list without any problems. For example, I had created a list of 100 coupon codes via the bulk generation option and I went back a few months later and changed the number of codes to 200 and it generated 100 new codes and added it to the list of the 100 previously generated codes. It saved the old codes and just added 100 more.
I attempted this again today and instead of adding an additional 100 coupon codes to the bulk list it re-generated all the codes and the previous list of bulk codes was completely wiped out. Since this happened I really am reluctant to try and add any more codes to an existing list. Wiping out a bunch of existing codes that have already been issued could be a huge problem. Is there something I did to trigger a complete redo of the bulk list? Can I do anything to prevent this happening in the future or should I just refrain from adding bulk codes to an existing list and just do a separate run by way of a completely new coupon?

Comments

wodenx’s picture

Assigned: AcidGhost » wodenx
Category: support » bug

I see what probably happened. Because of the way bulk codes are generated, increasing the bulk number works without altering existing codes only if the new number is within a certain range (it must have the same number of digits when converted to hex). There's no fix for this without breaking existing codes. When I have a chance, I'll add an error message to the coupon edit form that prevents making a change that will invalidate existing codes.

AcidGhost’s picture

Thanks for looking into this wodenx. This makes a lot of sense seeing as I was going from 200 codes (hex=c8) to 300 codes (hex=c12). For the time being I will make sure I check the hex code when I am increasing numbers to make sure there is not an issue but a warning dialog box would be spectacular in the future.

davidarthur’s picture

Just been stung by this one :(

We've been generating extra codes and handing them out, then all of a sudden users a re reporting their codes aren't working :(
As wodenx pointed out, it works some times and then all of a sudden it breaks all of the existing codes.

Need to find a quick solution to allow the old codes to work...

davidarthur’s picture

I've created an alternative method of storing bulk codes as a temporary solution, might be useful to someone else...
I've created a table uc_coupons_bulk. This is a table with 2 columns, cid and code. All of the codes that are missing (or have been overwritten) can be added to this table. They will then match and work just as if they were generated from the bulk seed.


  // Look through bulk coupons.
  $result = db_query("SELECT cid, code, data, bulk_seed FROM {uc_coupons} WHERE status = 1 AND bulk = 1 AND valid_from < %d AND (valid_until = 0 OR valid_until > %d)", time(), time());
  while ($coupon = db_fetch_object($result)) {

    // check bulk coupons table
    $tablecheck = db_query("SELECT cid, code FROM {uc_coupons_bulk} WHERE code='%s' AND cid=%d", $code, $coupon->cid);
    while ($tmp = db_fetch_object($tablecheck)){
      return uc_coupon_load($coupon->cid);
    }
davidarthur’s picture

Issue summary: View changes

edited wording