Changing invoice templates for Ubercart 2.3 and later

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.

jstrachan's picture
Offline
Joined: 03/01/2010
Juice: 35
Administration Theme

It should be noted that the templates must be in the folder of your administration theme if it is different from your main site theme. Creating symlinks from the administration theme folder functions as a workaround.

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 164
Re: Changing invoice templates for Ubercart 2.3 and later

Beware that translations that had tokens in them are now broken ...

For example this was in my translation interface:

Original text:
Thanks for your order, [order-first-name]!

Japanese:
[order-last-name]さんご注文いただき誠にありがとう御座います!

This is now broken and I'm not sure how to fix the translations.

jstrachan's picture
Offline
Joined: 03/01/2010
Juice: 35
Re: Re: Changing invoice templates for Ubercart 2.3 and later

All of the translatable strings seem to have gone from [token] to !token.

If you search for "Thanks" in the Translate interface, you'll see there is a new string, "Thanks for your order, !order_first_name!", which is the one you're looking for.

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 164
Re: Re: Re: Changing invoice templates for Ubercart 2.3 and late

Thanks for the tip, that makes sense. However why is the translate interface showing this:

Built-in interface: Thanks for your order, [order-first-name]!

Why didn't the update also update that string? (I'll be the first to say I'm not very cognizant of how translation works)

jstrachan's picture
Offline
Joined: 03/01/2010
Juice: 35
Re: Re: Re: Re: Changing invoice templates for Ubercart 2.3 and

That string still exists in the translation table but just won't get used anymore.

My understanding of the translation system is that when the t() function is called to translate a string, it adds the string to the translation table (if it isn't already there) and returns the appropriate translation (if there is one). The Order Invoice templates used to call t("Thanks for your order, [order-first-name]!") but now call t("Thanks for your order, !order-first-name!") so both strings are in the table and able to be translated.

I don't know whether the Ubercart folks would have been able to update the translation table with upgrade from 2.2 to 2.3...

Thankfully there should be too many strings affected by this change. The only ones I can spot are:

  • Thanks for your order, [order-first-name]! --> Thanks for your order, !order-first-name!
  • If you need to check the status of your order, please visit our home page at [store-link] and click on "My account" in the menu or login with the following link: --> If you need to check the status of your order, please visit our home page at !store_link and click on "My account" in the menu or login with the following link:
  • To learn more about managing your orders on [store-link], please visit our help page. -->To learn more about managing your orders on !store_link, please visit our help page.
totsubo's picture
Offline
Joined: 11/12/2009
Juice: 164
Re: Re: Re: Re: Re: Changing invoice templates for Ubercart 2.3

Thanks for the very informative reply!

After a bit of testing I think the problem I am having has nothing to do with translations and that there is a bug in the templating code. Even when I send an email in English the tokens are not replaced Smiling

I've posted in the Support forum here:

http://www.ubercart.org/forum/support/17588/new_invoice_templates_not_pa...

And have raised a bug report here:

http://drupal.org/node/869368

Iella's picture
Offline
Joined: 07/31/2010
Juice: 10
Easy mode please

Hi

I'm new to this and learning slowly by trial and error (mostly error at this point)

I've just updated some modules and now got the message:

Failed: 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.

So I've come here and frankly I don't understand a word of the post above.

Is there any kind person out there that can translate the above to baby language please ie - open file XXX go to line XX and repace YYYY with ZZZ or go to modules -> orders -> and select XX

Thanks (hopefully)

jstrachan's picture
Offline
Joined: 03/01/2010
Juice: 35
Hi Iella, It's possible that

Hi Iella,

It's possible that none of this applies to you. If you've never done anything to customize the invoices that are sent out from your site then Ubercart is just warning you that the old-style invoice template files still exist. Just go to /sites/all/modules/ubercart/uc_order/templates (the first part of that path may be different for you..) and delete admin.itpl.php and customer.itpl.php. Things should then just work as they always did.

If you have customized your invoices then things get more complicated. You'll need a working knowledge of Drupal theming and will have to migrate your changes from the old template files to the new ones: uc_order-admin.tpl.php and uc_order-customer.tpl.php. As was mentioned in the original doc, you should be copying those new template files (as well as uc_order.tpl.php) to your own theme directory before making any changes.

I'm afraid I can't get much more specific than that since the details really depend on your setup. Hopefully I've at least pointed you in the right direction to find the answers you need.

Marijke's picture
Offline
Joined: 08/05/2010
Juice: 4
customer.itpl.php to uc_order_customer.tpl.php

Hello,

First of al I'm very happy with Ubercart, my compliments to all develepors. After the last Drupal update I seem to have a different e-mail for my customers. That is the third time I think I have to change the template order/itpl.php after an update. I'm only a simple user and I do not understand how to do it this time. And also I was not warned about a new template-file. I translated it to Dutch and added some text and modified it to my liking.

Now what exactly do I have to do to make it the way I like it? I still have the old customer.itpl.php. Do I have to make the changes I want again in the new file? Or is there an easier way to do this?

Thank you,

Marijke

marcus178's picture
Offline
Joined: 04/13/2009
Juice: 113
Emailed invoice template wrong

I have added the templates to my theme folder and my customizations are display correctly in admin but the when the customer receives their emailed invoice they just get the default one.

I have even tried adding a new template with a completely different name and selecting this in conditional actions but they are still receiving the default template.

It's almost as if condition actions it not aware of the new template files that I've added to my theme.

tazir's picture
Offline
Joined: 01/27/2010
Juice: 44
Just qoute the explanation
Quote:

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.
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."

So, is not about adding new file, either you create module for this or override the existing template.

marcus178's picture
Offline
Joined: 04/13/2009
Juice: 113
Re: Changing invoice templates for Ubercart 2.3 and later

I had created the module, but just worked the reason it wasn't working was because I'm using a different theme for my admin, if you you 2 themes you need to add the template files to both themes so that they show correctly in admin and when mailed to the customer.

shiloe's picture
Offline
Joined: 08/12/2010
Juice: 11
Problem adding new invoice?

I've added the new invoice to the /ubercart/docs/hooks.php, but I can't get it to show up under Administration › Store administration › Configuration › Order Settings. Am I adding it to the wrong location or is there something else I need to do to get it to show?

mophyz's picture
Offline
Joined: 08/16/2010
Juice: 4
Custom Tokens in Ubercart Invoice Template

I had custom tokens in the customer.itpl template before Ubercart upgraded to support themed invoices and my invoices don't apprear to insert this information anymore. I modified the uc_order-customer.tpl to the new format and it still doesn't not provide the information. Any ideas on how to fix this?

Old version of customer.itpl (uses the extra field panes module for these new tokens):
Delivery Date:[extra-shipping-delivery_date]

New version of uc_order-customer.tpl

<?php
echo $extra-shipping-delivery_date;
?>
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: Custom Tokens in Ubercart Invoice Template

Remember, the dashes get turned into underscores, so it should be

<?php
 
echo $extra_shipping_delivery_date;
?>
pamreed's picture
Offline
Joined: 03/22/2010
Juice: 33
Does not seem to be working?

Hi

Ok. I updated to ubercart 2.4. Now I am trying to get my custom order invoice to work in the new configurations. I read through the documents 'Changing invoice templates for Ubercart 2.3 and later'. The document is not the clear to me.

How does it associated the types to a custom tpl.php file?

This is what i have done.
1. converted my 3 old itpl.tpl to tpl.pl as follows
ctbylights-customer.itpl.php to uc_order-ctl-customer.tpl.php - for Conditional Action invoice email to customer
ctbylights-admin.itpl.php to uc_order-ctl-admin.tpt.php - for Conditional Action invoice email to admin
ctybylights-printinvoice.itpl.php to uc_order-ctl-printinv.tpl.php - for the Order Settings On-site invoice template
2. Since I have my own templates need to create the a module to implement the hook. So I created the following module uc_ctl_templates. Create the info file and the .module file. This is what I have in it.
function uc_ctl_templates_uc_invoice_templates() {
return array('ctl-admin', 'ctl-customer','ctl-printinv');
}

3. Upload and Enable the module
4. I see the templates options available in both the Conditional actions and Order Setting. So I set them accordingly.

So the issue is neither the admin, customer or Invoice or Invoice Printable screen are actually using the templates chosen. So what I am doing wrong? Again I do not see where or how it associates the type to the tpl.php file.

Need help quickly if possible planning to go live with this site next week. Now this is holding me up, need to re-test for the update.

Thank you,
Pam

Update:

Ok I finally got it to work but not like it was suppose to. One thing I have wrong is the custom tpl.php need to have uc_order in the name. The other issue is it does not work unless you put the templates in the uc_order/templates directory. Once I made those changes the custom templates started being used. I would think this is bug for the whole idea was to move the custom templates to the themes directory. Now have to figure out why PayPal not working after the update.

Thank you,
Pam

madmadmadaxe's picture
Offline
Joined: 06/28/2010
Juice: 25
Attributes on uc_order-customer.tpl.php

Hi,

Have changed my invoice templates over since the update and everything is working great except the attributes on the invoice templates. They are saying "array" for the content descriptions. They never used to say this prior to the update. Is there something that needs to be changed with them?

<?php
if (is_array($product->data['attributes']) && count($product->data['attributes']) > 0) {
?>
<?php
foreach ($product->data['attributes'] as $key => $value) {
                                echo
'<li>'. $key .': '. $value .'</li>'
?>

That is the original code that worked great.

grobot's picture
Offline
Joined: 04/12/2008
Juice: 289
Issue on Drupal.org

Since it's not already linked from this page: http://drupal.org/node/295423

Giant Robot - for campaign, charity, ngo & online store solutions - www.giantrobot.co.nz

arguila's picture
Offline
Joined: 09/02/2010
Juice: 11
ubercart to read uc_order new template file

Im having huge problems trying to get my ubercart installation to read new custom customer in

/admin/store/ca/uc_checkout_customer_notification/edit/actions

i read the thread and still haven¨t been able to proceed. i didnt have any custom template files earlier so it should have been any problems. However, tried everything, started by copying all uc_order templates into my own theme and created a new one mycustomer.itpl.php and uc_order-mycustomer.tpl.php which didnt work, then i tried to alter customer template without changing the name without any luck. seems that ub is not reading templates inside the theme directory.

so my question is: what do i need to do to let ubercart read my uc_order templates in my theme?

Do i need to add preprocess function in my template file in my theme?

or do I need to add the snippet above

<?php
function uc_order_uc_invoice_templates() {
  return array(
'admin', 'customer');  (and include "my-customer" new template)
}
?>

in uberact/docs/hooks.php, if yes how do i do that?

or do I need to build a module?

I also tried to add my "my-customer" template into the module itself sites/modules/ubercart/uc_order/templates) with no luck

any help appreciated

THANKS

glennpratt's picture
Offline
Joined: 09/09/2010
Juice: 8
What worked for me...
  1. All of these changes required a hard cache clear (drush cc all), we're using a modified branch of Pressflow, so you mileage may vary.
  2. Overrides for default templates and custom templates all live in our theme. For example, this is the path to a custom template.

    sites/all/themes/(our theme)/ubercart/uc_order-group-admin.tpl.php

    Then that entire directory is symlinked into our admin theme.

  3. The hook to enable our custom template lives in a custom module where we set a bunch of other ubercart settings (apci_commerce.module):
    <?php
    /**
    * Implementation of hook_uc_invoice_templates().
    *
    * @return
    *  array of invoice types this module provides.
    */
    function apci_commerce_uc_invoice_templates() {
      return array(
    'group-admin');
    }
    ?>
md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
Should custom invoices be placed in the site theme folder

Getting the order invoice templates moved into the theme layer is a great plus!

I was wondering however why they must be placed in the administrative theme (if its different from the site theme). I thought that the site theme would have been the obvious place for such template files? The first comment on this post talks about using symlinks to get around the problem, linking the invoice templates held in an admin theme to your sites frontend theme. If however you run a multisite setup, all sharing a single admin theme backend(i.e rootcandy), you run into the same problem as the previous invoice system, with shared sites being able to choose/see each others invoices.

Does anyone know why uc_order searches the admin theme and not the site theme by default? I'm sure there must be a reason that I'm missing.

Cheers,
Mark

glennpratt's picture
Offline
Joined: 09/09/2010
Juice: 8
Re: Changing invoice templates for Ubercart 2.3 and later

I'm not sure ubercart can control where the theme system looks for template overrides.

Would be nice of it would pick up templates from other modules.

grobot's picture
Offline
Joined: 04/12/2008
Juice: 289
why admin theme not site theme?

Does anyone know why uc_order searches the admin theme and not the site theme by default? I'm sure there must be a reason that I'm missing.

Because the admin theme is active when you are selecting the templates to use.

You could likely copy "dummy" template files into your admin theme and have it work just the same.

They just have to have the same name as the templates which will be looked for when the order is confirmed.

Giant Robot - for campaign, charity, ngo & online store solutions - www.giantrobot.co.nz

arguila's picture
Offline
Joined: 09/02/2010
Juice: 11
Re: Changing invoice templates for Ubercart 2.3 and later

I followed the Pamreed example and i created a module and change configuration in order settings and conditional actions.

but i keep getting the error: "Unable to send e-mail. Please contact the site administrator if the problem persists." after checking out.

my module i called: uc_jentas_templates

and my uc_jentas_templates.info file consist of

;;$Id$ uc_jentas_templates.info,v 1.2 2009/01/27 14:03:28 longwave Exp $
name = jentas invoice template
description = Allow invoice templates to become jentas template
dependencies[] = uc_order
package = Ubercart
core = 6.x

and my uc_jentas_templates.module consist of:

<?php
function uc_jentas_templates_uc_invoice_templates() {
  return array(
'jentas-customer');
}
?>

i enabled the module and changed "costumer" to "jentas-costumer" in order settings and conditional actions without complications.

then i created uc_order-jentas-costumer.tpl.php and placed it in my theme directory and in uc_order/templates dir.

in addition i placed uc_order.tpl.php and uc_order-costumer.tpl.php in my theme dir but dont seems to work.

the error message gives me a hint that ubercart stopped getting the costumer template but for some reason it cannot get jentas-costumer template.

has anybody dealt with same problem?

moby's picture
Offline
Joined: 10/05/2008
Juice: 205
invoice template not using store date format

Hi guys,

post 2.3/4 upgrade

the default customer invoice doesnt obey the store dates configuration.

       <?php echo $order_date_created; ?>

our store config is set for australia d/M/Y

but invoices are printing M/d/Y

how do i fix this?

sterg17's picture
Offline
Joined: 05/20/2009
Juice: 126
Help! Bulk Operations

Hello

Im using bulk operations....and im getting an error when trying to print my invoices. I upgraded like everyone else did up to.

The error is in this code:

function _uc_order_bulkops_view_invoice($order) {
$output = uc_order_load_invoice($order, 'print', variable_get('uc_cust_order_invoice_template', 'customer'));
return $output;
}

What's wrong with it? still calling the old invoices???

moby's picture
Offline
Joined: 10/05/2008
Juice: 205
drupal date config..

it used drupals date config..

/admin/settings/date-time

jlyndesyn's picture
Offline
Joined: 09/20/2010
Juice: 9
Thank you for the "Easy" notes!

Thank you to "jstrachan" who replied to "Iella." I'm a newbie, had just installed Ubercart, done a few configurations, and then saw the need for upgrade. I saw the same "Failed" notice and starting searching for reasons. Your notes are exactly what I needed.
Thanks!

sterg17's picture
Offline
Joined: 05/20/2009
Juice: 126
why us no one helping??? Is

why us no one helping???

Is no one else using the Bulk Order Operations?? how are you guys printing multiple invoices???

fcortez's picture
Offline
Joined: 10/11/2010
Juice: 18
hook_uc_invoice_templates

Just to clarify this post.

The function is:
Function (http://api.lullabot.com/uc_order_uc_invoice_templates):

<?php
function hook_uc_invoice_templates() {
  return array(
'custom', 'custom2');
}
?>

To use:

1. Create a custom module and add the code below to your custom module
Replace 'mycustommodule' with the name of your module
Replace custom, custom2 with the name of your template.
Example:
uc_order-custom.tpl.php = custom
uc_order-example.tpl.php = example

<?php
function mycustommodule_uc_invoice_templates() {
  return array(
'custom', 'custom2');
}
?>

2. Copy uc_order.tpl.php from sites/all/modules/ubercart/uc_order/templates/ and add it to your root template folder. sites/all/themes/(theme folder). This is needed due to the way the Drupal template system works.

3. Add uc_order-custom.tpl.php and uc_order-custom2.tpl.php (and any additional template specified by mycustommodule_uc_invoice_templates) to your root template folder. sites/all/themes/(theme folder). Flush your theme registry and your done. You should now be able to use your custom email template.

A good starting point is copying a template file from the sites/all/modules/ubercart/uc_order/templates/ and changing the name to uc_order-yourcustomtemplate.tpl.php.

sterg17's picture
Offline
Joined: 05/20/2009
Juice: 126
Re: Changing invoice templates for Ubercart 2.3 and later

is custom the only way to do it?

fcortez's picture
Offline
Joined: 10/11/2010
Juice: 18
Re: Changing invoice templates for Ubercart 2.3 and later

See post above. I've rewritten it to clarify it some more.

To answer your question no. 'custom' is just an example. change custom to the name of your template. Example: uc_order-example.tpl.php = example.

obrienmd's picture
Offline
Joined: 12/04/2009
Juice: 28
Re: Changing invoice templates for Ubercart 2.3 and later

Not working for me, even following the steps above... I've added the hook, and can select the new template, but am unsure about the template placement:

I've tried both in our admin theme directory (in sites/all/themes/themename of our multisite setup) and this site's theme directory in (sites/sitename/themes/themename), but upon anyone clicking through the review order page, both seem to return the error:

"We're sorry. An error occurred while processing your order that prevents us from completing it at this time. Please contact us and we will resolve the issue as soon as possible."

In the watchdog, I can see UberCart reporting "An empty order made it to checkout! Cart order ID:" (no order ID shows... this is for anonymous checkout).

Thoughts?

samuelsov's picture
Offline
Joined: 10/13/2010
Juice: 5
How to add a template file in a module

I finally find out how to make it work in a module, here are the steps :

  1. create a template uc_order-my-template-type.tpl.php in your module directory
  2. Implementation of hook_uc_invoice_templates
    function my_module_uc_invoice_templates() {
      return array('my-template-type');
    }
  3. Implementation of hook_theme_registry_alter
    function my_module_theme_registry_alter(&$theme_registry) {
      // so that templates are searched in my_module directory if not found in uc_order
      if (!empty($theme_registry['uc_order'])) {
        $theme_registry['uc_order']['theme paths'][] = drupal_get_path('module', 'my_module');
      }
    }

With this, you can now change existing conditionnal actions or create new ones using the new type "my-template-type"

fcortez's picture
Offline
Joined: 10/11/2010
Juice: 18
Did you Flush your theme Registry?

Did you copy uc_order.tpl.php and your uc_order-customtemplate.tpl.php to your sites/all/themes/themename folder?
And then Flush your theme Registry? If you don't flush your theme registry it won't find them.

obrienmd's picture
Offline
Joined: 12/04/2009
Juice: 28
Re: How to add a template file in a module

Did all this, same error - but now I've got it down to anonymous checkouts only. Very strange.

However, ubercart recognizes my new template from the module directory...

To answer the question below, I've cleared my theme registry many, many times Smiling

obrienmd's picture
Offline
Joined: 12/04/2009
Juice: 28
Re: Changing invoice templates for Ubercart 2.3 and later

Hrm... on top of all this anonymous business, it seems as though while orders go through for logged in users, they receive an e-mail based on the standard template, though my template is selected in the conditional actions setup - on the only rule left enabled at this point...

Ugh.

fcortez's picture
Offline
Joined: 10/11/2010
Juice: 18
Re: Re: Changing invoice templates for Ubercart 2.3 and later

See post #30 it works.

obrienmd's picture
Offline
Joined: 12/04/2009
Juice: 28
Re: Changing invoice templates for Ubercart 2.3 and later

I've seen post #30, thank you. I've tried it. I've also tried the more complicated module setup seen a few posts above this one...

Could #30 not be working because we are using a multisite setup, and our theme is not in /sites/all, rather in its site's specific directory?

I've also tried on the admin theme, which IS in /sites/all...

fcortez's picture
Offline
Joined: 10/11/2010
Juice: 18
Re: Re: Changing invoice templates for Ubercart 2.3 and later

I believe this is your problem:
Our theme is not in /sites/all, rather in its site's specific directory?

Sorry I don't have an answer for your scenario.

obrienmd's picture
Offline
Joined: 12/04/2009
Juice: 28
Re: Changing invoice templates for Ubercart 2.3 and later

Right, you may be right - however, this is unavoidable in our case... I was hoping the module solution from a few comments back would work, however it does not.

buysnakewine's picture
Offline
Joined: 03/31/2009
Juice: 105
what is the template encoding ? uft8 ?

Hello,

As i see that you made an invoice template in Japanese can you tell me what is the template encoding ? uft8 ?

I mean, how to use non English letters in the template ?

And which Editor do you use, notepad++ ?

Thank for info.

sterg17's picture
Offline
Joined: 05/20/2009
Juice: 126
Bulk Order Operations

Can someone please advise how they got this to work with the bulk operations module??

I cant print my invoices in bulk?? What do you guys recommend?

jeeberpow's picture
Offline
Joined: 03/05/2009
Juice: 5
Hang ups and How I solved

Some hangups I had in this process:

1. Took a few read-throughs to catch that the default uc_order.tpl.php file had to be in my theme folder as well my custom templates.

2. Didn't see an obvious reference to HOW to flush the theme cache. I used the Devel module but apparently just doing a full flush on the performance page does it too.

3. This was the killer for me. Before I could get it to sending anything aside from the default templates (despite what the conditional actions said) I had to open each conditional action that had to do with emailing and click "Save predicate." That kicked things into gear.

As a side note, I'm sure there are logical reasons, but building a custom module just to add some email templates is pretty annoying.

md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
uberinvoice

I've thrown together a helper module that does the steps described throughout the thread above. I'll post if people want or is it overkill and people have got this working themselves?

davidw's picture
Offline
Joined: 05/27/2009
Juice: 100
I would use it

I could use a helper module. If you could post it, that would be great!

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 299
drush cc all doesn't help

I edited the file
uc_order-customer.tpl.php
in
sites/all/modules/ubercart/uc_order/templates

and I did a
drush cc all

But my emails being sent, are still the original ones. Why? What should I do?

jamienotweet's picture
Offline
Joined: 12/15/2010
Juice: 5
If the old template is still being emailed

You will need to update the conditional action for "E-mail customer checkout notification". When you edit the action, change the Invoice Template dropdown to your new template.

buysnakewine's picture
Offline
Joined: 03/31/2009
Juice: 105
Change the Invoice Template dropdown to your new template ?

Hello,

"change the Invoice Template dropdown to your new template"

Do you know if i can add a new template in the template folder on my server and then select this new template here ?

Thanks.

gjmokcb's picture
Offline
Uber Donor
Joined: 11/17/2008
Juice: 61
Correct procedure--this worked for me

Copy the uc-order_customer.tpl.php file from the ubercart/uc_orders/templates folder, and save it in your site’s ADMINISTRATIVE theme folder. Rename the template file to match your new theme name: uc-order_newtheme.tpl.php. Copy the “dummy” uc_order.tpl.php from the same ubercart location to the same administrative theme folder.

Customize the new template file to suit your purposes. Do not edit the dummy template file.

Create a module folder named “uc_custom_themes” or whatever. In that folder, create a standard .info file (uc_custom_themes.info) and a .module file (uc_custom_themes.module). The module file should read as follows:

<?php
function uc_custom_themes_uc_invoice_templates() {
  return array(
'newtheme');
}
?>

Note that your function prefix should match your module name: function [module name]_uc_invoice_templates.

For more than one custom theme, extend the array: ‘newtheme’, ‘newtheme2’, newtheme3’.

Enable the module. Set the new template as your choice in conditional actions. Save the conditional action’s predicate again (important). Clear all the site caches (important).

Done.

barbs75's picture
Offline
Joined: 01/18/2011
Juice: 5
Adding/changing variables available in custom templates

Hey guys,

I have bespoke template files working no problemo, however my issue now is that i need to pump some profile data from my registered user into the template.

Above in the documentation it mentions that there is a hook_preprocess_uc_order(). Does anyone know where this lives? I have done a find on this in the ubercart module folder, and not getting any results....wanna see what it does so i can override this hook.

cheers in advance
Craig

ToddFur's picture
Offline
Joined: 07/13/2010
Juice: 19
Need help

Hi,

I need help with this. So here is what I have done:

1) copied uc_order-customer_bb.tpl.php, uc_order-admin_bb.tpl.php, and uc_order.tpl.php to /drupal/themes/acquia_slate directory
- I only modified the first 2 files to my needs and directly copied the 3rd one from the uc_order/templates dir
- In the first 2 files, I did replace

<td width="98%">
  <?php echo $order_email; ?>
</td>

2) I created a new module directory under /drupal/sites/all/modules/uc_custom_themes
-I created 2 files: uc_custom_themes.info and uc_custom_themes.module
-In those files:

<?php
function uc_custom_themes_uc_invoice_templates() {
  return array(
'customer_bb','admin_bb');
}
?>

Now when I go try enable this module, it doesn't appear there, what am I missing?

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Hi, Did you make an regular

Hi,

Did you make an regular .info file. If you did, the module should pop up!
Greetings, Martijn

md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
Helper module

I posted ages ago about putting this up, sorry it completely slipped my mind.

https://github.com/md-2/UberInvoice

direct download link: https://github.com/md-2/UberInvoice/tarball/master

Cheers,
Mark

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Hi Mark, Thanks for building

Hi Mark,

Thanks for building this!
I think the uber_invoce.info should be the following:

; $Id: uber_invoice.info,v 1 Exp $
name = Uber Invoice
description = Helper module to move Ubercart Invoice Templates out of Ubercart folder for customisation
package = "Ubercart - extra"
core = "6.x"
dependencies[] = uc_order

Then it is nicely placed under Ubercart extra, and has the correct dependency, right?
Wouldn't it also not be better to rename the package to uc_invoice?

EDIT: There is also a bug in! Parse error: syntax error, unexpected ',', expecting ')' in /sites/all/modules/ubercart/uc_uberInvoice/uber_invoice.module on line 12
One , to many in that line. Easy fix..please fix in github.
Would also great if you made it a drupal.org/project/uberinvoice (or uc_invoice). Then people can add there own invoice templates etc... to share!

EDIT2: I added a t() function, the main reason I need a custom template, is that I added tax to the template.
But on drupal translate I do not see the t() text.... Am I missing something?
Do the template files (tpl.php) also need to be placed on my theme, or on admin theme, or on both?
Right now I changed the uc_order-ubercustomer.tpl.php in the module folder, is that enough?

Thanks for your reply in advance!
Greetings, Martijn

md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
Hi Martijn

I'll get onto this ASAP, can't believe I committed the file with an error in.... should have a fresh commit up this afternoon

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Re: Hi Martijn

Hi, can you please explain then also the working?
I added the module under ubercart with changed .info and bugfix.
How do I use the templates. Do I need to copy them to the theme folder? Why is an added t() not shown within Drupal Admin Language?
Thanks a lot in advance again for your reply!

greetings,
Martijn

johandenhollander's picture
Offline
Joined: 09/27/2007
Juice: 79
Re: Re: Hi Martijn

There is a readme file in the module folder. It explains all that you need to know.
You need to edit the .tpl files that are provided in the module folder. (uc_order-uberadmin.tpl.php and uc_order-ubercustomer.tpl.php)

I succesfully tried the module today. Thanks for providing it to us md-2.

Kind regards,
Johan

md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
Improvments

The module https://github.com/md-2/UberInvoice was written very roughly. I''ve added a quick readme to give the minimal outline on how to use. If better documentation / commenting is needed I will take some time to write some.

If anyone has any suggestions / finds any bugs for this helper module, report / suggest them on https://github.com/md-2/UberInvoice/issues and I'll try and sort them out.

Cheers,
Mark

eurotransient's picture
Offline
Joined: 02/18/2011
Juice: 19
How to change invoice from order admin screen?

I've managed to get my custom invoices changed over to the new template theming system and they work wonderfully using conditional actions. Unfortunately, when I view invoices in the order admin screen at

/admin/store/orders/[order #]/invoice

My custom invoices aren't showing up there. I've changed the order settings at /admin/store/settings/orders/edit/basic so that the on-site invoice template is the one I customized and flushed all caches, but still nothing.

The biggest issue for me here is that I occasionally need to update some of the order information manually and when I do this, I use the "mail invoice" button on the order's admin screen (/admin/store/orders/[order #]/invoice/mail). When I do this, the customer ends up getting the default invoice templates, not my custom ones.

As an experiment, I hacked the core uc_order-customer.tpl.php file in my uc_order/templates directory and my changes carried through to the order admin screen. I definitely do NOT want to keep those hacks in place, though, so any help in getting the on-site invoice template to reflect my custom templates would be greatly appreciated.

marvzz's picture
Offline
Joined: 10/07/2010
Juice: 17
Email Invoice Templates

Will the procedure of putting the template on the ADMINISTRATION THEME folder be recognized on the front end where customers are sent the invoice after payment?

md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
Get it all working?

Hi Martijn,

Just a quick check that you got everything working, I've not had much time to reply lately.

Cheers,
Mark

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Hi Mark, Yes I got things

Hi Mark,

Yes I got things working. I would very much see others custom made uc_order-ubercustomer.tpl.php templates, so we can learn from each other.
Would be great to have a drupal.org/project/uberInvoice page for that.
I would very much like to show more images in the order email.
Thanks for checking my status!

greetings, Martijn

bunset's picture
Offline
Joined: 03/06/2011
Juice: 33
subscribing

I dont know how to include direct debit payments details in my invoice.
Some tip is very welcome.

UC ver 2.4

Thanks.

md-2's picture
Offline
Joined: 11/04/2008
Juice: 52
By the power of GIT

I was holding off creating a project page for this helper module until the GIT migration. I've now done so, well a sandbox at least, need to do a coding standards review etc before applying for full project status. Anyway the sandbox can be found at http://drupal.org/sandbox/markdavies/1088200, feel free to report issues, suggestions etc.

Cheers,
Mark

break's picture
Offline
Joined: 03/26/2011
Juice: 7
How to make custom template show up?

I read through this thread, but I am still unclear on how to make my custom invoice show up for conditional action. Here is what I did so far:

1. I made a copy of the "uc_order-customer.tpl.php" file in the /sites/all/modules/ubercart/uc_order/templates directory and named it "uc_order-sales-confirmation.tpl.php"

2. I heavily edited the new "uc_order-sales-confirmation.tpl.php" file, including making its second line like this
// $Id: uc_order-sales-confirmation.tpl.php,v 1 2011/03/28 15:45:09 gaborpor Exp $

3. I cleared the site's cache at /admin/settings/performance

4. I was expecting to see the new template showing up as an option besides the default "admin" and ""customer" at /admin/store/ca/uc_checkout_admin_notification/edit/actions (in other words at the "action" section of the "E-mail admin checkout notification:" conditional action), but it didn't.

What do I need to do/change to make it happen?

Thank you.

johandenhollander's picture
Offline
Joined: 09/27/2007
Juice: 79
@Break, You missed point

@Break,

You missed point zero!

0. Download and install this module and read the README:
https://github.com/md-2/UberInvoice

break's picture
Offline
Joined: 03/26/2011
Juice: 7
Thank you

Thank You, That was it.. My templates are up and running. The module you created came really handy.

Looks like I was reading this thread in the wrong chronological order and glanced over the most recent messages, while paid too much attention to year old ones.

davidw's picture
Offline
Joined: 05/27/2009
Juice: 100
Me too

I too would really benefit from seeing other sites' invoice templates. (since I'm not a coder)

fwright's picture
Offline
Joined: 03/21/2009
Juice: 108
Attribute prices on invoice

Mark, I have been trying to find a solution to a problem for several months now, but no one has been able to help me. I am wondering how to add the price adjustment of an attribute to an invoice? For example, if you have a T-shirt product and the user is upcharged $2 for an xxxl, how do you get that listed on the invoice?

As it stands now, ubercart lists the attributes on the invoice, and it lists the total price, but it does not list the individual attribute price adjustments on the invoice.

thanks a ton for any advice,

Fred

arskipaski's picture
Offline
Joined: 02/17/2010
Juice: 99
Re: Re: Custom Tokens in Ubercart Invoice Template

Hey, and how would this look in D7?

I've a bunch of custom tokens defined under the order type on my site, and they used to display perfectly in D6 with the above code, but in D7 all I'm getting is
Notice: Undefined variable: my_token_name in include() (line 132 of ...sites/all/modules/ubercart/uc_order/templates/uc-order--customer.tpl.php).

Thanks

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3277
Re: Re: Re: Custom Tokens in Ubercart Invoice Template

That's because you didn't properly upgrade your custom code for Drupal 7. Token is now in core, and the token hooks are different. See http://drupal.org/update/modules/6/7

<tr>.
arskipaski's picture
Offline
Joined: 02/17/2010
Juice: 99
Re: Changing invoice templates for Ubercart 2.3 and later

I have, actually.. it seems that the theme function for these template only takes certain variables now, like order and other stuff.

If you also look at the order tokens themselves, defined by uc_order, like "total", "created" etc., then those aren't available in the template either or so it seems. in fact, you have to write $order_total, which is not what the token is called - ['uc_order']['total'], but clearly something else, like the "total" attribute of the "order" object, right?

arskipaski's picture
Offline
Joined: 02/17/2010
Juice: 99
Re: Changing invoice templates for Ubercart 2.3 and later

so, any thoughts on tokens in D7 order templates? Smiling

arskipaski's picture
Offline
Joined: 02/17/2010
Juice: 99
Re: Changing invoice templates for Ubercart 2.3 and later

And looking at the "template_preprocess_uc_order" function I see that the token variables have a slightly different naming structure in D7 - the "uc_" is removed and the type name, i.e. "order_" is prefixed. So substituting "uc_" by "order_" fixes the issue!

kdmarks's picture
Offline
Joined: 07/09/2011
Juice: 9
Using profile variables in uc_order-admin.tpl.php

I'd like to print custom fields from the user's profile in the email that gets sent to admin. I've tried the following with no luck.

<?php
profile_load_profile
($variables['account']);
print
$profile['Personal Information']['profile_address']['#value'];
?>

I thought profile_load_profile would give me access to the profile variables. Or do I need to make them available through _preprocess_uc_order? If so, I'd be really grateful for an example _preprocess_uc_order. Preprocess functions are still a bit beyond me.

kdmarks's picture
Offline
Joined: 07/09/2011
Juice: 9
Re: Using profile variables in uc_order-admin.tpl.php

Finally got this to work. To print custom fields from the user's profile in the email that is sent to store admins when an order is placed:

<?php global $user ;?>
<?php profile_load_profile($user); ?>
<?php echo t('Address:'); ?> <?php print $user->profile_address; ?>
<?php echo t('Phone:'); ?> <?php print $user->profile_phone; ?>

Hope this helps someone else!

cwrighta70's picture
Offline
Joined: 01/31/2011
Juice: 34
kdmarks, I'm having a problem

Nevermind...fixed my issue

Jake11's picture
Offline
Joined: 12/07/2010
Juice: 20
Uber Invoice module and PayPal Standard double notifications

Many thanks to the contributions in this forum, particularly the clear explanation and custom module created by md-2 in post #54. This module has enabled my templates to override the default invoice templates as expected. However, I am now receiving 2 copies of each invoice for both the customer and admin notification. I have tried many solutions to eliminate the double notifications by changing Conditional Actions as described in other forums, but so far, they either make the emails not deliver at all or still deliver 2 notifications. I am wondering if anyone else has had this issue. If so, any help would be appreciated.

I am using Ubercart 6.x-2.4 with PayPal Standard and Acquia Drupal 6.19.

johandenhollander's picture
Offline
Joined: 09/27/2007
Juice: 79
Jake, Did you disable this

Jake,

Did you disable this module to see if the double emails are gone?
If not your problem has a different cause.

Jake11's picture
Offline
Joined: 12/07/2010
Juice: 20
Double Emails with PayPal and Ubercart Notification

Thanks for the quick reply. I was finally able to fix the problem. As noted by several others in various forums, PayPal WTS apparently triggers a second email notification if Conditional Actions aren't set to "Check the order status" with the argument set to "In Checkout". This seems to be the answer I was looking for, using only PayPal WTS. There are also additional settings that may need to be applied to distinguish PayPal from other payment methods if others are enabled.
To clarify the exact steps I took for Ubercart/PayPal beginners like myself:

1. In Paypal, I set up the account to be a business account, and in Profile > More Options > My Sellings Tools > Website Preferences, I took the following steps. Turn on Auto Return with the following Return URL (https://www.example.com/cart/checkout/complete (substituting your site name in place of example.com, and change to http:// if not using SSL). Use this and not http://www.example.com/uc_paypal/wps/complete, which was intended for an older version of Paypal/ Ubercart. All the other settings should be off, with the exception of "Paypal Account Optional,", I left IPN off, and it seems OK.

2. I uploaded md-2's UberInvoice Module(thanks again), followed the instructions and edited the templates to my liking.

2. In Drupal/Ubercart > Store Administration > Conditional Actions > Triggers I edited the E-mail Admin and E-mail Customer notifications to enable new templates in the Actions Tab. This is also where I had to add a Condition Group to the email notification in the Conditions Tab to "Check the Order Status" with the argument set to "In Checkout".

Hope this helps someone else with a similar problem.
It took a while for my notification email to show up after changing the settings for the first time also, for some reason, which added to my confusion. Now it seems to work well though.

Jake11's picture
Offline
Joined: 12/07/2010
Juice: 20
Double Emails with PayPal and Ubercart Notification

As an update to my last post, it turns out I had to do further configuring to the Conditional Actions to get a single email sent for both the Admin and Customer invoices. The above settings were sending only one email to the customer, but no email was sent to the admin with the settings I described.

What finally fixed it was using no extra conditions on the Admin email and leaving it enabled, but adding an action to the customer notification email to also send an admin notification email. I also had to leave the Customer Checkout settings configured as I said earlier.
Not sure why this works this way, but at least I got it to work. I hope further releases of Ubercart will make this a little more straightforward for sending invoices - I was about to resign to the fact it was either 2 copies or none! . I suppose a lot of it has to do with PayPal and the way it notifies Ubercart of events.

schtink's picture
Offline
Joined: 09/19/2011
Juice: 18
Duplicate Emails - Kludgy Solution

I've been having trouble with duplicate emails as well using Paypal WPS. My main concern was that my customer would call me to ask why they got two emails and if they had been charged twice.

I could not use the solution above as I am running Ubercart 3 and the Conditional Actions are obsolete in my version.

I've create a somewhat kludgy solution till there is an official patch to fix this. With my fix your customer will still get two order confirmations, but they will be different.

First, make a copy of the uc-order--customer.tpl.php template file located in ubercart/uc_order/templates. Rename it to something else and wrap the following PHP code around the entire template.

<?php
if (strstr($order_comments, 'submitted through PayPal') == TRUE) {

// echo whatever text you'd like to appear in the email in lieu of the order

}
else {
?>

// The original contents of uc-order--customer.tpl.php here

<?php } ?>

How this works... When Paypal sends the IPN which trigger the order email again it also sends through a comment in the variable $order_comments. It's something like "Payment of $123 USD submitted through PayPal." The original $order_comments variable in the first order email does not contain this value. It should have whatever your customer's comments normally are. So this helps delineate which email is which and the PHP does the rest.

It's not a perfect solution, and I can't say it will work for everyone, but it's working for me, and it's much better than modifying the actual module to get it to do what I want.

Hope this helps somebody else!

revilo's picture
Offline
Joined: 11/30/2010
Juice: 21
Re: Helper module

I had the same problem as #24 -- Error message when using custom template.
Using this helper module in #54 works for me, however, not if I select the "ubercustomer" option on the admin page (Store administration » Conditional actions » Edit predicate) as suggested in the readme.
What I ended up doing was to directly edit the uc_order-customer.tpl.php supplied with the module. It says not to do this in the readme, but it's the only thing I've found that doesn't give an error. It's also overriding the original file, so I don't really see any problem with it.
Thanks for the module!

rhendrix's picture
Offline
Joined: 11/02/2011
Juice: 4
invoice emails NOT sending

I'm having the opposite issue from some other people. My emails are NOT sending when a new order is placed. Stopped working after I upgraded to latest Ubercart yesterday. I've since downloaded and installed the module from above to help get the templates listed back on the conditonal actions pages, but emails are still not going out to customers or to admin.

MattMoody's picture
Offline
Joined: 12/01/2011
Juice: 4
Edit uc_order-admin.tpl.php in admin UI

How can I edit messages and add some variable to uc_order-admin.tpl.php using admin interface? Maybe something like menu edit page with dragable table of items: reorder items, check enable or not, edit labels... or with CKEditor and patterns

franravi's picture
Offline
Joined: 12/19/2011
Juice: 4
UC 3.0-rc3

I had to solve this same problem for Ubercart 3.0-rc3 (Drupal 7).

After many failed attempts involving a module with hook_uc_invoice_templates and hook_theme_registry_alter, the solution that finally worked for us was to make a copy of both uc_order--customer.tpl.php and uc_order--admin.tpl.php and drop down to my default theme's root folder. Please note that both files uses two dashes. Just for reference, both files can be taken from /ubercart/uc_order/templates.

You should then do a hard clear cache to make sure changes applies (I recommend to use "drush cc all", twice for better results).

nksahu's picture
Offline
Joined: 03/09/2012
Juice: 4
Extra Global Token

I created some extra token to be used in "check payment"
Hope this will help someone

ucextrainfoinemail.info

; $Id$
name = UberCart ExtraInfo
description = UberCart ExtraInfo in email template
core = 6.x
version = "6.x-3.5"
project = "ubercartextrainfoinmail"
datestamp = "1244161838"

ucextrainfoinemail.module

<?php
// $Id$
/**
* @file
* This is a custom module
*/

function ucextrainfoinemail_token_list($type = 'all') {
  $tokens = array();

  if ($type == 'global' || $type == 'all') {
    $tokens['global']['uc_store_name']        = t('Store Name.');
    $tokens['global']['uc_store_company']     = t('Store Company.');
    $tokens['global']['uc_store_street1']     = t('Store Street Address 1.');
    $tokens['global']['uc_store_street2']     = t('Store Street Address 2.');
    $tokens['global']['uc_store_city']        = t('Store City.');
    $tokens['global']['uc_store_zone']        = t('Store Zone.');
    $tokens['global']['uc_store_postal_code'] = t('Store Zip Code.');
    $tokens['global']['uc_store_country']     = t('Store Country');
    $tokens['global']['uc_check_policy']      = t('Store Check Policy.');
  }
  if ($type == 'node' || $type == 'all') {
    // Node tokens here.
  }

  return $tokens;
}

function ucextrainfoinemail_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'global':
     $values['uc_store_name']        = variable_get('uc_store_name', '');
     $values['uc_store_company']     = variable_get('uc_store_company', '');
     $values['uc_store_street1']     = variable_get('uc_store_street1', '');
     $values['uc_store_street2']     = variable_get('uc_store_street2', '');
     $values['uc_store_city']        = variable_get('uc_store_city', '');
     $values['uc_store_zone']        = variable_get('uc_store_zone', '');
     $values['uc_store_postal_code'] = variable_get('uc_store_postal_code', '');
     $values['uc_store_country']     = variable_get('uc_store_country', 840);
     $values['uc_check_policy']      = variable_get('uc_check_policy', '');
      break;
    case 'node':
      // Node tokens here.
      break;
  }
  return $values;
}

With the help of these extra token, I was able to put the check mailing address in the Email