Index: uc_order/uc_order.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_order/Attic/uc_order.admin.inc,v
retrieving revision 1.1.2.28
diff -u -p -r1.1.2.28 uc_order.admin.inc
--- uc_order/uc_order.admin.inc 18 Nov 2009 21:08:06 -0000 1.1.2.28
+++ uc_order/uc_order.admin.inc 28 Dec 2009 19:42:33 -0000
@@ -1071,9 +1071,7 @@ function uc_order_view($order, $view = '
}
if ($view == 'invoice') {
- $output = uc_order_load_invoice($order, 'print', variable_get('uc_cust_order_invoice_template', 'customer'));
- $output .= '
'
- .'
';
+ $output = theme('uc_order', $order, 'print', variable_get('uc_cust_order_invoice_template', 'customer'));
print $output;
exit();
}
@@ -1679,7 +1677,7 @@ function uc_order_add_product_form($form
* 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;
Index: uc_order/uc_order.ca.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_order/uc_order.ca.inc,v
retrieving revision 1.1.2.28
diff -u -p -r1.1.2.28 uc_order.ca.inc
--- uc_order/uc_order.ca.inc 20 Oct 2009 20:58:07 -0000 1.1.2.28
+++ uc_order/uc_order.ca.inc 28 Dec 2009 19:42:33 -0000
@@ -1242,7 +1242,7 @@ function uc_order_action_email_invoice($
$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);
Index: uc_order/uc_order.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_order/uc_order.module,v
retrieving revision 1.12.2.36
diff -u -p -r1.12.2.36 uc_order.module
--- uc_order/uc_order.module 18 Nov 2009 22:24:02 -0000 1.12.2.36
+++ uc_order/uc_order.module 28 Dec 2009 19:42:34 -0000
@@ -317,6 +317,11 @@ function uc_order_init() {
*/
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 @@ function uc_order_mail($key, &$message,
$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 @@ function uc_order_uc_message() {
return $messages;
}
+/**
+ * Implementation of hook_uc_invoice_templates().
+ */
+function uc_order_uc_invoice_templates() {
+ return array('admin', 'customer');
+}
+
/*******************************************************************************
* Callback Functions, Forms, and Tables
******************************************************************************/
@@ -1523,92 +1535,81 @@ function _get_order_screen_titles() {
/**
* Load a formatted invoice with an order's data.
*/
-function uc_order_load_invoice($order, $op = 'view', $template = 'customer') {
- static $invoice;
+//function uc_order_load_invoice($order, $op = 'view', $template = 'customer') {
+function template_preprocess_uc_order(&$variables) {
+ $variables['thank_you_message'] = FALSE;
- if (isset($invoice[$order->order_id][$template])) {
- return $invoice[$order->order_id][$template];
+ switch ($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;
}
- $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'],
- );
- }
+ $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');
+ }
+ if (!is_array($variables['line_items'])) {
+ $variables['line_items'] = array();
+ }
+ usort($variables['line_items'], 'uc_weight_sort');
- ob_start();
- require($file);
- $output = ob_get_contents();
- ob_end_clean();
+ $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);
}
- $output = token_replace($output, 'global');
- $output = token_replace($output, 'order', $order);
+ foreach ($full->tokens as $key => $token) {
+ $value = $full->values[$key];
+ $variables[str_replace('-', '_', $token)] = $value;
+ }
- $invoice[$order->order_id][$template] = $output;
- return $output;
+ $variables['template_file'] = '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';
+ $templates = drupal_map_assoc(module_invoke_all('uc_invoice_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);
- }
+ // Sort the template names alphabetically.
+ sort($templates);
return $templates;
}
Index: uc_order/templates/admin.itpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_order/templates/admin.itpl.php,v
retrieving revision 1.4.4.6
diff -u -p -r1.4.4.6 admin.itpl.php
--- uc_order/templates/admin.itpl.php 17 Aug 2009 21:27:53 -0000 1.4.4.6
+++ uc_order/templates/admin.itpl.php 28 Dec 2009 19:42:34 -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 @@ foreach ($products as $product) {
-[order-comments]
+
Index: uc_order/templates/customer.itpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_order/templates/customer.itpl.php,v
retrieving revision 1.5.2.9
diff -u -p -r1.5.2.9 customer.itpl.php
--- uc_order/templates/customer.itpl.php 21 Sep 2009 14:34:49 -0000 1.5.2.9
+++ uc_order/templates/customer.itpl.php 28 Dec 2009 19:42:34 -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 @@
- [order-email]
+
|
@@ -72,18 +72,18 @@
- [order-billing-address]
+
- [order-billing-phone]
+
|
- [order-shipping-address]
+
- [order-shipping-phone]
+
|
@@ -96,7 +96,7 @@
- [order-total]
+
|
@@ -104,7 +104,7 @@
- [order-payment-method]
+
|
@@ -131,7 +131,7 @@
- [order-link]
+
|
@@ -141,7 +141,7 @@
- [order-shipping-method]
+
|
@@ -151,7 +151,7 @@
- [order-subtotal]
+
|
@@ -192,7 +192,7 @@
- [order-total]
+
|
@@ -256,7 +256,7 @@
- help page.'); ?>
+ help page.', array('!store_link' => $store_link, '!store_help_url' => $store_help_url)); ?>
@@ -267,7 +267,7 @@
- [store-link] [site-slogan]
+
|