You are here

function uc_addresses_preprocess_uc_order in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.module \uc_addresses_preprocess_uc_order()

Preprocess variables for Ubercart Order invoices.

The address labels are overwritten with addresses formatted using the Ubercart Addresses address formats (in case such format exists).

Parameters

array $variables: Order variables for in the invoice template.

Return value

void

1 call to uc_addresses_preprocess_uc_order()
uc_addresses_preprocess_uc_packing_slip in ./uc_addresses.module
Preprocess variables for Ubercart Packing slips.

File

./uc_addresses.module, line 1860
Adds user profile address support to Ubercart.

Code

function uc_addresses_preprocess_uc_order(&$variables) {
  $order =& $variables['order'];

  // Generate tokens to use as template variables.
  $token_info = token_info();

  // Remove default_shipping, default_billing, aid, uid, created and modified.
  // These fields are not useful in order context as they never contain values
  // in these context.
  unset($token_info['tokens']['uc_addresses']['default_shipping']);
  unset($token_info['tokens']['uc_addresses']['default_billing']);
  unset($token_info['tokens']['uc_addresses']['aid']);
  unset($token_info['tokens']['uc_addresses']['uid']);
  unset($token_info['tokens']['uc_addresses']['created']);
  unset($token_info['tokens']['uc_addresses']['modified']);
  $replacements = array();
  if (isset($order->uc_addresses)) {
    foreach ($order->uc_addresses as $address_type => $address) {
      if ($address instanceof UcAddressesAddress) {
        $types = array(
          'uc_addresses' => $address,
        );

        // Generate tokens.
        $replacements[$address_type] = token_generate('uc_addresses', drupal_map_assoc(array_keys($token_info['tokens']['uc_addresses'])), $types);

        // Overwrite address labels.
        $address_label = uc_addresses_format_address($address, 'order_view');
        $variables['order_' . $address_type . '_address'] = $address_label;
        $variables[$address_type . '_address'] = $address_label;
      }
    }
  }
  foreach ($replacements as $type => $tokens) {
    foreach ($tokens as $token => $value) {
      $key = 'uc_addresses_' . $type . '_' . $token;
      $key = str_replace('-', '_', $key);
      $key = str_replace(':', '_', $key);
      $variables[$key] = $value;
    }
  }
}