Hello, all!

I have created a new invoice template by copying the current uc-order-admin.tpl.php file and renaming it uc-order-custom.tpl.php. This file is placed in ubercart/uc_order/templates. I have also copied this file to sites/all/themes/MYTHEME/invoice (which also contains uc-order-customer.tpl.php and uc-order.tpl.php). Unfortunately, I do not see my new template as an option in the Conditional Actions? I only see admin and customer.

Can someone please help me with this? I've been reading through this link: http://www.ubercart.org/docs/developer/17385/changing_invoice_templates_...

...but cannot seem to find an answer.

Thanks!
Chris

Comments

cwrighta70’s picture

Hopefully I'm not breaking forum rules, but I'm bumping this thread so that it gets seen (as it is now on the 3rd page).

forward-media’s picture

You have to implement hook_uc_invoice_templates()

/**
* Implementation of hook_uc_invoice_templates().
*/
function your_module_uc_invoice_templates() {
return array('customer-your_template');
}

I Know you wrote on 1. Feb but i hope this helps you :)

tobi

cwrighta70’s picture

Thanks tobi. We found the same thing, except we just added our new template to the current list:

/**
 * Implementation of hook_uc_invoice_templates().
 */
function uc_order_uc_invoice_templates() {
  return array('admin', 'customer', 'custom');
}

So, for those of you searching for an answer to this, here is your answer! First, the array shown in the code sample above is ONLY set during the installation process. You must edit the sites/all/modules/ubercart/uc_order/uc_order.module file. Search for the function shown in the above code sample, and add the name of your template to this array.

Please note that your template name must be using this naming convention: uc_order-templateName.tpl.php, and the name that you will add to the array is only templateName.

Hope this solves your problem as well.
Chris

shaneonabike’s picture

And ironically placing this in your theme folder doesn't actually work. You totally have to place this in the ubercart folder which is well annoying and pretty un-Drupal...

NewZeal’s picture

The correct implementation for this is something like

function your_module_uc_invoice_templates() {
  return array('your_template');
}

where your template name is uc_order-your_template.tpl.php and is placed in uc_order/templates

jonathan_hunt’s picture

If you want to keep your template out of Ubercart's directories (this makes it easier to update Ubercart later) try:

/**
 * Implements hook_uc_invoice_templates().
 */
function your_module_uc_invoice_templates() {
  return array('your_template');
}

/**
 * Add our own theme hook for our invoice.
 * Implements hook_theme().
 */
function your_module_theme($existing, $type, $theme, $path) {
  $path = drupal_get_path('module', 'your_module');
  $theme_hooks = array(
  'uc_order__your_template' => array(
    'template' => 'uc-order--your_template',
    'path' => $path . '/templates',
    'variables' => array(
        'order' => NULL,
        'op' => 'view',
        'template' => 'customer',
        'thank_you_message' => FALSE,
        'help_text' => FALSE,
        'email_text' => FALSE,
        'store_footer' => FALSE,
        'business_header' => FALSE,
        'shipping_method' => FALSE,
      ),
    ),
  );

  return $theme_hooks;
}

This assumes you have a templates/ directory in your module's directory.

squarecandy’s picture

In Drupal 6 ubercart I could just put uc-order--customer.tpl.php in my theme templates folder and it just worked.
Now we need to make a custom module to override the invoice?

malcolmp’s picture

very helpful - thanks

agileware’s picture

Another solution which is a variation to the above.

Create a small module and then alter the theme registry, this works for both the customer invoice and admin invoice (which typically can be quite troublesome).

This forces Ubercart to use your customised template for both customer & admin. After enabling the module, clear the theme registry (drush cc theme-registry or drush cc all).

Simple module structure:
tax_invoice/tax_invoice.info
tax_invoice/tax_invoice.module
tax_invoice/templates/uc-order.tpl.php

tax_invoice/tax_invoice.module

<?php
function tax_invoice_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'tax_invoice');

  $theme_registry['uc_order__customer']['template'] = 'uc-order';
  $theme_registry['uc_order__customer']['path'] =  $path . '/templates';

  $theme_registry['uc_order__admin']['template'] = 'uc-order';
  $theme_registry['uc_order__admin']['path'] =  $path . '/templates';
}

tax_invoice/templates/uc-order.tpl.php*
* This is your customised invoice template.

Agileware are a team of local Drupal developers in Australia, https://agileware.com.au
Agileware support and host Drupal, CiviCRM and WordPress websites.
Contact Agileware today at https://agileware.com.au/contact

Dan Z’s picture

I put together a module that makes this process a lot easier for Ubercart 3 / Drupal 7. It's currently at http://drupal.org/sandbox/Z-TwistBooks/1778488.

jainparidhi’s picture

hello DanZ

Thanks for your module! It sounds very promising and god send for a newbie like me. I tried installing the snapshot tar.gz file from 8 days ago but Drupal doesnt allow me to install it cause it does not contain any .info file. Any guidance is appreciated.

Thanks,

PJ

Dan Z’s picture

It does contain an info file. Did you name the extract directory uc_invoice_templates?

Also, please problems (issues) on the project page, so I can find them more easily!

Finally, this module needs more external testing. Once you get it installed, please report if it works or not.

DanZ’s picture

A non-sandbox version of the module is now available at http://drupal.org/project/uc_register_invoice. It should be easier to install.

--
www.ztwistbooks.com. Math books that are actually fun.

DanZ’s picture

For all you Googlers out there, the solutions for Drupal 7 are completely documented at http://drupal.org/node/1867700.

--
www.ztwistbooks.com. Math books that are actually fun.