I have a need for a large number of coupons. If I choose to create 10,000 coupons, this module actually creates 10,000 coupons and stores them in the database. The way that uc_coupon does bulk coupons is it stores a seed, and then indexes into that seed to generate coupons. It's a more efficient approach than creating and storing the actual codes.

Comments

pcambra’s picture

Patches are welcome :)

favrik’s picture

Issue summary: View changes

I need this for yesterday. xD I'll contribute patches, just want to know if the following strategy is good for sharing (this is actually for 2.x-dev).

  • Remove Coupon Suffix: makes it easier to add validation and find the bulk coupon via query
    SELECT * FROM commerce_coupon 
    WHERE bulk = 1
    AND code = SUBSTRING('BULK7B62246D' FROM 1 FOR CHAR_LENGTH(code));
    

    However, finding the code if we still use a Prefix, shouldn't be that hard.

  • Add Code exists validation for the Prefix only. Users cannot create single or bulk coupons that start with the Coupon Prefix of an existing Bulk Coupon
  • Add new fields: bulk_seed, bulk_number, and bulk_length to commerce_coupon schema. Could also be added via FIeld API but it seems overkill on one hand, and a bit of mixing stuff in the same table on the other.
  • This might be the most drastic change: modify commerce_coupon_load_by_code in commerce_coupon module, by adding a call to module_invoke or module_invoke_all when a coupon code is not found via the EFQ. For example:
    $result = module_invoke('commerce_coupon_batch', 'coupon_code_not_found', $code, $type);
    

Thoughts?

favrik’s picture

On second thought, I think creating a coupon_batch entity (or just a table) where the template used to create the coupons is stored plus a map between coupon batch template and coupon ids is better. This would keep simplicity in the coupon redeem process, and improve the UI so that you can easily identify coupons created in the bulk process, and possibly bulk-delete and bulk-edit them.

EDIT: Initial work on that idea: https://github.com/favrik/commerce_coupon_batch/tree/favs