You are here

function uc_coupon_get_bulk_code in Ubercart Discount Coupons 6

Same name and namespace in other branches
  1. 5 uc_coupon.module \uc_coupon_get_bulk_code()
  2. 7.3 uc_coupon.module \uc_coupon_get_bulk_code()
  3. 7.2 uc_coupon.module \uc_coupon_get_bulk_code()

Generate a single bulk coupon code.

6 calls to uc_coupon_get_bulk_code()
uc_coupon_find in ./uc_coupon.module
Load a coupon (single or bulk) from the supplied code.
uc_coupon_handler_field_codes::pre_render in views/uc_coupon_handler_field_codes.inc
Expand the coupon codes for each coupon in the result set.
uc_coupon_print in ./uc_coupon.admin.inc
Print a coupon, or set of bulk coupons.
uc_coupon_purchase_view in uc_coupon_purchase/uc_coupon_purchase.pages.inc
Display a list of purchased coupons.
uc_coupon_token_values in ./uc_coupon.module
Implementation of hook_token_values().

... See full list

File

./uc_coupon.module, line 380
Provides discount coupons for Ubercart.

Code

function uc_coupon_get_bulk_code($coupon, $id) {

  // If this coupon has been validated, then $coupon->code is already a bulk code.
  if (isset($coupon->valid)) {
    $prefix = substr($coupon->code, 0, strlen($coupon->code) - $coupon->data['bulk_length']);
  }
  else {
    $prefix = $coupon->code;
  }
  $id = str_pad(dechex($id), strlen(dechex($coupon->data['bulk_number'])), '0', STR_PAD_LEFT);
  $length = strlen($prefix) + $coupon->data['bulk_length'];
  return strtoupper(substr($prefix . $id . md5($coupon->bulk_seed . $id), 0, $length));
}