The system for customizing or overriding invoices in Ubercart was inflexible. uc_order hardcoded a single template directory to scan for possible templates (uc_order/templates). Additional templates may be created but must live in that directory. Amongst other things this then made Ubercart upgrades tricky. Additionally, templates were in a non standard .itpl.php format and are not overridable at the theme layer.
The solution to overcome these limitations is to convert the invoice system to use the Drupal theme layer. Invoice templates are converted from .itpl.php to .tpl.php, e.g. customer.itpl.php becomes uc_order-customer.tpl.php. Also, token values are changed from the format
<td width="98%">
[order-email]
</td>to standard template variables
<td width="98%">
<?php echo $order_email; ?>
</td>Themes can now override invoice templates as per normal Drupal theming practices, e.g. copy uc_order-customer.tpl.php into your theme dir for customisation. Note that due to the way Drupal's theme layer works the dummy uc_order.tpl.php must be copied as well.
Also introduced is hook_uc_invoice_templates() which allows modules to declare new "types" of invoice templates (other than 'admin' and 'customer'). This replaces the old behaviour of invoice types being declared directly in the invoice file name, e.g. customer.itpl.php. If you have created other invoice templates for your site, you will need to create a module to implement this hook so that you can choose those templates in the UI. It should return an array of the invoice types:
<?php
function uc_order_uc_invoice_templates() {
return array('admin', 'customer');
}
?>If your site doesn't have a custom module for this kind of hook, and you only have one custom invoice template, you can override uc_order-customer.tpl.php instead. Be sure to check your Conditional Actions that email invoices and change their settings to use the "customer" invoice template.
The biggest win for the new template and token handling is the preprocess hook. hook_preprocess_uc_order() lets you add anything as a variable to the invoice template. The default template_preprocess_uc_order() already adds all of the order tokens, though other modules could define new tokens. The main benefit is that if you don't like the way the tokens are generated, then you have the opportunity to completely change them in the preprocess function, no need to override an entire template just to change a few template values.




