diff --git docs/hooks.php docs/hooks.php
index 8167a6c..3359abd 100644
--- docs/hooks.php
+++ docs/hooks.php
@@ -1389,6 +1389,20 @@ function hook_uc_form_alter(&$form, &$form_state, $form_id) {
}
/**
+ * 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
diff --git uc_order/templates/admin.itpl.php uc_order/templates/uc_order-admin.tpl.php
similarity index 73%
rename from uc_order/templates/admin.itpl.php
rename to uc_order/templates/uc_order-admin.tpl.php
index 1b08800..be71cba 100644
--- uc_order/templates/admin.itpl.php
+++ uc_order/templates/uc_order-admin.tpl.php
@@ -8,10 +8,10 @@
?>
@@ -43,5 +43,5 @@ foreach ($products as $product) {
-[order-comments]
-
+
+
\ No newline at end of file
diff --git uc_order/templates/customer.itpl.php uc_order/templates/uc_order-customer.tpl.php
similarity index 85%
rename from uc_order/templates/customer.itpl.php
rename to uc_order/templates/uc_order-customer.tpl.php
index df3e95b..b25edd3 100644
--- uc_order/templates/customer.itpl.php
+++ uc_order/templates/uc_order-customer.tpl.php
@@ -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]
+
@@ -140,7 +140,7 @@
- [order-date-created]
+
@@ -150,7 +150,7 @@
- [order-shipping-method]
+
@@ -160,7 +160,7 @@
- [order-subtotal]
+
@@ -201,7 +201,7 @@
- [order-total]
+
@@ -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]
+
diff --git uc_order/templates/uc_order.tpl.php uc_order/templates/uc_order.tpl.php
new file mode 100644
index 0000000..4a67420
--- /dev/null
+++ uc_order/templates/uc_order.tpl.php
@@ -0,0 +1,11 @@
+ '
.'';
print $output;
@@ -1679,7 +1679,7 @@ function uc_order_add_product_form($form_state, $order, $node) {
* 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;
diff --git uc_order/uc_order.ca.inc uc_order/uc_order.ca.inc
index e5f6f62..b3a4ba3 100644
--- uc_order/uc_order.ca.inc
+++ uc_order/uc_order.ca.inc
@@ -1242,7 +1242,7 @@ function uc_order_action_email_invoice($order, $settings) {
$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);
diff --git uc_order/uc_order.install uc_order/uc_order.install
index 481e5a8..3f06d6e 100644
--- uc_order/uc_order.install
+++ uc_order/uc_order.install
@@ -1139,3 +1139,19 @@ function uc_order_update_6014() {
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 the template upgrade guide on Ubercart.org for details.');
+ }
+
+ return $ret;
+}
diff --git uc_order/uc_order.module uc_order/uc_order.module
index 87fb591..b8963ff 100644
--- uc_order/uc_order.module
+++ uc_order/uc_order.module
@@ -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, $params) {
$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
******************************************************************************/
@@ -1521,94 +1533,82 @@ function _get_order_screen_titles() {
}
/**
- * 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();
- }
+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;
+ }
- $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(
+ '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;
+ // Add template file suggestions, default to customer template.
+ $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';
+ $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;
}