You are here

function uc_coupon_get_bulk_code in Ubercart Discount Coupons 7.3

Same name and namespace in other branches
  1. 5 uc_coupon.module \uc_coupon_get_bulk_code()
  2. 6 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()
UcCouponController::buildContent in ./uc_coupon.entity.inc
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.

... See full list

File

./uc_coupon.module, line 356
Provides discount codes and gift certificates 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 = drupal_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));
}