function template_preprocess_uc_coupon_certificate in Ubercart Discount Coupons 7.3
Same name and namespace in other branches
- 6 uc_coupon.module \template_preprocess_uc_coupon_certificate()
- 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 1951 - Provides discount codes and gift certificates for Ubercart.
Code
function template_preprocess_uc_coupon_certificate(&$variables) {
$coupon = $variables['coupon'];
// Create variables for each user-added field.
$fields = field_info_fields();
foreach ($fields as $name => $field) {
if (in_array('uc_coupon', array_keys($field['bundles']))) {
$items = field_get_items('uc_coupon', $coupon, $name);
$variables[$name] = $items;
}
}
$variables['value'] = theme('uc_coupon_discount', array(
'coupon' => $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 > REQUEST_TIME;
$variables['valid_from'] = format_date($coupon->valid_from, 'custom', variable_get('date_format_uc_store', 'm/d/Y'));
$variables['valid_until'] = format_date($coupon->valid_until, 'custom', variable_get('date_format_uc_store', 'm/d/Y'));
}
else {
$variables['not_yet_valid'] = FALSE;
$variables['valid_from'] = FALSE;
$variables['valid_until'] = FALSE;
}
$variables['max_uses_per_user'] = isset($coupon->data['max_uses_per_user']) ? $coupon->data['max_uses_per_user'] : NULL;
$variables['include'] = array();
$variables['exclude'] = array();
if (isset($coupon->data['product_types'])) {
foreach ($coupon->data['product_types'] as $type) {
$variables['include'][] = node_type_get_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_term_load($tid);
$variables[$key][] = $term->name;
}
}
// Merge in global tokens.
$info = token_info();
foreach ($info['types'] as $type => $type_info) {
if (empty($type_info['needs-data']) && $type != 'current-user' && $type != 'current-date') {
$type_key = !empty($type_info['type']) ? $type_info['type'] : $type;
if (!empty($info['tokens'][$type_key])) {
foreach (array_keys($info['tokens'][$type_key]) as $token) {
$variables[str_replace('-', '_', $type_key) . '_' . str_replace('-', '_', $token)] = token_replace("[{$type_key}:{$token}]");
}
}
}
}
if (isset($variables['coupon']->data['base_cid'])) {
$variables['theme_hook_suggestions'][] = 'uc_coupon_certificate__base_' . $variables['coupon']->data['base_cid'];
}
$variables['theme_hook_suggestions'][] = 'uc_coupon_certificate__' . $variables['coupon']->cid;
}