You are here

function template_preprocess_uc_coupon_certificate in Ubercart Discount Coupons 6

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

Preprocess template for a printed coupon certificate.

See also

uc_coupon-certificate.tpl.php

File

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

Code

function template_preprocess_uc_coupon_certificate(&$variables) {
  $coupon = $variables['coupon'];
  $variables['value'] = uc_coupon_format_discount($coupon);
  $variables['display_name'] = check_plain($coupon->name);
  $n = stripos($variables['display_name'], 'purchased by');
  if ($n) {
    $variables['display_name'] = substr($variables['display_name'], 0, $n - 1);
  }
  if ($coupon->valid_until) {
    $variables['not_yet_valid'] = $coupon->valid_from > time();
    $variables['valid_from'] = format_date($coupon->valid_from, 'custom', variable_get('uc_date_format_default', 'm/d/Y'), 0);
    $variables['valid_until'] = format_date($coupon->valid_until, 'custom', variable_get('uc_date_format_default', 'm/d/Y'), 0);
  }
  else {
    $variables['not_yet_valid'] = FALSE;
    $variables['valid_from'] = FALSE;
    $variables['valid_until'] = FALSE;
  }
  $variables['max_uses_per_user'] = $coupon->data['max_uses_per_user'];
  $variables['include'] = array();
  $variables['exclude'] = array();
  if (isset($coupon->data['product_types'])) {
    foreach ($coupon->data['product_types'] as $type) {
      $variables['include'][] = node_get_types('name', $type);
    }
  }
  if (isset($coupon->data['products'])) {
    $key = isset($coupon->data['negate_products']) ? 'exclude' : 'include';
    foreach ($coupon->data['products'] as $nid) {
      $node = node_load($nid);
      $variables[$key][] = $node->title;
    }
  }
  if (isset($coupon->data['skus'])) {
    foreach ($coupon->data['skus'] as $sku) {
      $variables['include'][] = t('SKU') . ' ' . $sku;
    }
  }
  if (isset($coupon->data['terms'])) {
    $key = isset($coupon->data['negate_terms']) ? 'exclude' : 'include';
    foreach ($coupon->data['terms'] as $tid) {
      $term = taxonomy_get_term($tid);
      $variables[$key][] = $term->name;
    }
  }

  // Merge in global tokens.
  $tokens = token_get_values();
  foreach ($tokens->tokens as $key => $token) {
    $value = $tokens->values[$key];
    $variables[str_replace('-', '_', $token)] = $value;
  }
  if (isset($variables['coupon']->data['base_cid'])) {
    $variables['template_files'][] = 'uc_coupon-certificate-base-' . $variables['coupon']->data['base_cid'];
  }
  $variables['template_files'][] = 'uc_coupon-certificate-' . $variables['coupon']->cid;
}