=== modified file 'docs/hooks.php' --- docs/hooks.php 2010-07-15 17:07:49 +0000 +++ docs/hooks.php 2010-07-15 19:53:06 +0000 @@ -1422,6 +1422,20 @@ } /** + * Add invoice templates to the list of suggested template files. + * + * Allows modules to declare new "types" of invoice templates (other than the + * default 'admin' and 'customer'). + * + * @return + * Array of template names that are available choices when mailing an + * invoice. + */ +function hook_uc_invoice_templates() { + return array('admin', 'customer'); +} + +/** * Convenience function to display large blocks of text in several places. * * There are many instances where Ubercart modules have configurable blocks of === modified file 'uc_order/templates/admin.itpl.php' --- uc_order/templates/admin.itpl.php 2009-07-24 17:06:02 +0000 +++ uc_order/templates/admin.itpl.php 2010-07-15 19:53:06 +0000 @@ -8,10 +8,10 @@ ?>

- [order-admin-link]
- [order-first-name] [order-last-name] - [order-email]
- [order-total]
- [order-shipping-method] +
+ -
+
+

@@ -43,5 +43,5 @@


-[order-comments] -

+ +

\ No newline at end of file === modified file 'uc_order/templates/customer.itpl.php' --- uc_order/templates/customer.itpl.php 2010-02-08 16:15:54 +0000 +++ uc_order/templates/customer.itpl.php 2010-07-15 19:53:07 +0000 @@ -17,16 +17,16 @@
- [site-logo] +
- [store-name]
- [site-slogan] +
+
- [store-address]
[store-phone] +
@@ -38,17 +38,17 @@ -

+

$order_first_name)); ?>

-

[new-username]
- [new-password]

+


+


- -

[site-login]

+ $store_link)); ?> +

@@ -62,7 +62,7 @@ @@ -72,18 +72,18 @@ @@ -96,7 +96,7 @@ @@ -104,7 +104,7 @@ @@ -131,7 +131,7 @@ @@ -140,7 +140,7 @@ @@ -150,7 +150,7 @@ @@ -160,7 +160,7 @@   @@ -201,7 +201,7 @@   @@ -265,7 +265,7 @@


- help page.'); ?> + help page.', array('!store_link' => $store_link, '!store_help_url' => $store_help_url)); ?>

@@ -276,7 +276,7 @@ -

[store-link]
[site-slogan]

+


=== modified file 'uc_order/uc_order.admin.inc' --- uc_order/uc_order.admin.inc 2010-04-13 13:26:40 +0000 +++ uc_order/uc_order.admin.inc 2010-07-15 19:53:07 +0000 @@ -1071,7 +1071,7 @@ } if ($view == 'invoice') { - $output = uc_order_load_invoice($order, 'print', variable_get('uc_cust_order_invoice_template', 'customer')); + $output = theme('uc_order', $order, 'print', variable_get('uc_cust_order_invoice_template', 'customer')); $output .= '
' .'
'; print $output; @@ -1679,7 +1679,7 @@ * Display an invoice in the browser, convert it to PDF, or e-mail it as HTML. */ function uc_order_invoice($order, $op = 'view') { - $output = uc_order_load_invoice($order, $op, variable_get('uc_cust_order_invoice_template', 'customer')); + $output = theme('uc_order', $order, $op, variable_get('uc_cust_order_invoice_template', 'customer')); if ($op == 'print') { print $output; === modified file 'uc_order/uc_order.ca.inc' --- uc_order/uc_order.ca.inc 2010-07-12 13:26:18 +0000 +++ uc_order/uc_order.ca.inc 2010-07-15 19:53:07 +0000 @@ -1243,7 +1243,7 @@ $recipients[] = trim($address); } - $settings['message'] = uc_order_load_invoice($order, $settings['view'], $settings['template']); + $settings['message'] = theme('uc_order', $order, $settings['view'], $settings['template']); if (empty($recipients)) { watchdog('ca', 'Attempted to e-mail an invoice with no recipient.', array(), WATCHDOG_ERROR); === modified file 'uc_order/uc_order.install' --- uc_order/uc_order.install 2010-04-01 18:22:25 +0000 +++ uc_order/uc_order.install 2010-07-15 19:53:07 +0000 @@ -1139,3 +1139,19 @@ return $ret; } + +/** + * Check for old .itpl.php invoice template files. + */ +function uc_order_update_6015() { + $ret = array(); + + $dir = drupal_get_path('module', 'uc_order') .'/templates'; + $templates = file_scan_directory($dir, '.*\.itpl\.php', array('.', '..', 'CVS'), 0, FALSE); + + if (!empty($templates)) { + $ret[] = array('success' => FALSE, 'query' => 'Old Ubercart .itpl.php invoice templates were found! These must be manually upgraded to use the Drupal theme layer. See [page] for details.'); + } + + return $ret; +} === modified file 'uc_order/uc_order.module' --- uc_order/uc_order.module 2010-03-23 13:41:18 +0000 +++ uc_order/uc_order.module 2010-07-15 20:03:57 +0000 @@ -317,6 +317,11 @@ */ function uc_order_theme() { return array( + 'uc_order' => array( + 'template' => 'uc_order', + 'path' => drupal_get_path('module', 'uc_order') .'/templates', + 'arguments' => array('order' => NULL, 'op' => 'view', 'template' => 'customer'), + ), 'uc_order_state_table' => array( 'arguments' => array('form' => NULL), ), @@ -520,7 +525,7 @@ $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed'; $message['subject'] = t('Your Order Invoice', array(), $langcode); $message['from'] = uc_store_email_from(); - $message['body'][] = uc_order_load_invoice($params['order'], 'admin-mail', variable_get('uc_cust_order_invoice_template', 'customer')); + $message['body'][] = theme('uc_order', $params['order'], 'admin-mail', variable_get('uc_cust_order_invoice_template', 'customer')); break; // Setup a custom e-mail defined by an action on a predicate. @@ -709,6 +714,13 @@ return $messages; } +/** + * Implementation of hook_uc_invoice_templates(). + */ +function uc_order_uc_invoice_templates() { + return array('admin', 'customer'); +} + /******************************************************************************* * Callback Functions, Forms, and Tables ******************************************************************************/ @@ -1521,94 +1533,85 @@ } /** - * Load a formatted invoice with an order's data. + * Preprocess a formatted invoice with an order's data. */ -function uc_order_load_invoice($order, $op = 'view', $template = 'customer') { - static $invoice; - - if (isset($invoice[$order->order_id][$template])) { - return $invoice[$order->order_id][$template]; - } - - $thank_you_message = FALSE; - - $file = drupal_get_path('module', 'uc_order') .'/templates/'. $template .'.itpl.php'; - if (file_exists($file)) { - switch ($op) { - case 'checkout-mail': - $thank_you_message = TRUE; - case 'admin-mail': - $help_text = TRUE; - $email_text = TRUE; - $store_footer = TRUE; - case 'view': - case 'print': - $business_header = TRUE; - $shipping_method = TRUE; - break; - } - - $products = $order->products; - if (!is_array($products)) { - $products = array(); - } - - $line_items = $order->line_items; - $items = _line_item_list(); - foreach ($items as $item) { - if (isset($item['display_only']) && $item['display_only'] == TRUE) { - $result = $item['callback']('display', $order); - if (is_array($result)) { - foreach ($result as $line) { - $line_items[] = array( - 'line_item_id' => $line['id'], - 'title' => $line['title'], - 'amount' => $line['amount'], - 'weight' => $item['weight'], - 'data' => $item['data'], - ); - } +function template_preprocess_uc_order(&$variables) { + $variables['thank_you_message'] = FALSE; + + 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['products'] = $variables['order']->products; + if (!is_array($variables['products'])) { + $variables['products'] = array(); + } + + $variables['line_items'] = $variables['order']->line_items; + $items = _line_item_list(); + foreach ($items as $item) { + if (isset($item['display_only']) && $item['display_only'] == TRUE) { + $result = $item['callback']('display', $variables['order']); + if (is_array($result)) { + foreach ($result as $line) { + $variables['line_items'][] = array( + 'line_item_id' => $line['id'], + 'title' => $line['title'], + 'amount' => $line['amount'], + 'weight' => $item['weight'], + 'data' => $item['data'], + ); } } } - if (!is_array($line_items)) { - $line_items = array(); - } - usort($line_items, 'uc_weight_sort'); - - ob_start(); - require($file); - $output = ob_get_contents(); - ob_end_clean(); - } - - $output = token_replace($output, 'global'); - $output = token_replace($output, 'order', $order); - - $invoice[$order->order_id][$template] = $output; - return $output; + } + if (!is_array($variables['line_items'])) { + $variables['line_items'] = array(); + } + usort($variables['line_items'], 'uc_weight_sort'); + + $types = array( + //'global' => NULL, + 'order' => $variables['order'], + ); + + $full = new stdClass(); + $full->tokens = $full->values = array(); + foreach ($types as $type => $object) { + $temp = token_get_values($type, $object, FALSE, $options); + $full->tokens = array_merge($full->tokens, $temp->tokens); + $full->values = array_merge($full->values, $temp->values); + } + + foreach ($full->tokens as $key => $token) { + $value = $full->values[$key]; + $variables[str_replace('-', '_', $token)] = $value; + } + + $variables['template_files'] = array( + 'uc_order-customer', + 'uc_order-'. $variables['template'], + ); } /** * Return an array of invoice templates found in ubercart/uc_order/templates. */ function uc_invoice_template_list() { - static $templates = array(); - - // If the template list hasn't already been loaded... - if (empty($templates)) { - // Get the path to the templates directory. - $dir = drupal_get_path('module', 'uc_order') .'/templates'; - - // Loop through all the files found in the directory. - foreach (file_scan_directory($dir, '.*\.itpl\.php', array('.', '..', 'CVS'), 0, FALSE) as $file) { - // Add them by name to the templates array, trimming off the extension. - $templates[] = substr($file->name, 0, strlen($file->name) - 5); - } - - // Sort the template names alphabetically. - sort($templates); - } + $templates = drupal_map_assoc(module_invoke_all('uc_invoice_templates')); + + // Sort the template names alphabetically. + sort($templates); return $templates; }
- [order-email] +

- [order-billing-address]
+


- [order-billing-phone]
+

- [order-shipping-address]
+


- [order-shipping-phone]
+
- [order-total] +
- [order-payment-method] +
- [order-link] +
- [order-date-created] +
- [order-shipping-method] +
- [order-subtotal] +
- [order-total] +