You are here

function template_preprocess_uc_order in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_order/uc_order.module \template_preprocess_uc_order()

Preprocesses a formatted invoice with an order's data.

See also

uc_order--admin.tpl.php

uc_order--customer.tpl.php

File

uc_order/uc_order.module, line 1758

Code

function template_preprocess_uc_order(&$variables) {
  $order =& $variables['order'];
  switch ($variables['op']) {
    case 'checkout-mail':
      $variables['thank_you_message'] = TRUE;
    case 'admin-mail':
      $variables['help_text'] = TRUE;
      $variables['email_text'] = TRUE;
      $variables['store_footer'] = TRUE;
    case 'view':
    case 'print':
      $variables['business_header'] = TRUE;
      $variables['shipping_method'] = TRUE;
      break;
  }
  $variables['shippable'] = uc_order_is_shippable($order);
  $variables['products'] = $order->products;
  $display = uc_order_product_view_multiple($order->products);
  foreach ($variables['products'] as &$product) {
    $product->title = check_plain($product->title);
    $product->model = check_plain($product->model);
    $product->total_price = render($display['uc_order_product'][$product->order_product_id]['total']);
    if ($product->qty > 1) {
      $product->individual_price = t('(!price each)', array(
        '!price' => uc_currency_format($display['uc_order_product'][$product->order_product_id]['price']['#price']),
      ));
    }
    else {
      $product->individual_price = '';
    }
    $product->details = '';
    if (!empty($product->data['attributes'])) {
      $attributes = array();
      foreach ($product->data['attributes'] as $attribute => $option) {
        $attributes[] = t('@attribute: @options', array(
          '@attribute' => $attribute,
          '@options' => implode(', ', (array) $option),
        ));
      }
      $product->details .= theme('item_list', array(
        'items' => $attributes,
      ));
    }
  }
  $variables['line_items'] = uc_order_load_line_items_display($variables['order']);
  $order->line_items = $variables['line_items'];

  // Generate tokens to use as template variables.
  $types = array(
    'uc_order' => $order,
  );
  $token_info = token_info();
  $replacements = array();
  foreach (array(
    'site',
    'store',
    'uc_order',
  ) as $type) {
    $replacements[$type] = token_generate($type, drupal_map_assoc(array_keys($token_info['tokens'][$type])), $types);
  }
  foreach ($replacements as $type => $tokens) {
    foreach ($tokens as $token => $value) {
      $key = str_replace('-', '_', $type . '_' . $token);
      $key = str_replace('uc_', '', $key);
      $variables[$key] = $value;
    }
  }

  // Add hook suggestions, default to customer template.
  $variables['theme_hook_suggestions'] = array(
    'uc_order__customer',
    'uc_order__' . $variables['template'],
  );
}