I'm migrating an Ubercart installation from D6 to D7.
The actual D6 version is using the extra field ucxf_cf_piva by referencing to it with the following correct syntax on the invoice tpl.php: $extra_extra_billing_cf_piva

Trying to do the same thing on D7 gives an empty result, instead of the cf_piva value.
I've tried the following with no luck:

print $extra_extra_billing_cf_piva;
print $order_extra_extra_billing_cf_piva;
print $orders_extra_extra_billing_cf_piva;
print $extra_extra_billing_ucxf_cf_piva;
print $order_extra_extra_billing_ucxf_cf_piva;
print $orders_extra_extra_billing_ucxf_cf_piva;

Comments

megachriz’s picture

For the Drupal 7 version of Extra Fields Pane, the implementation of tokens and template variables for the invoice of extra (address) fields has been moved to Ubercart Addresses. The pattern to use is now:
$uc_addresses_(address type)_(field name)

So, in your case this would be:
$uc_addresses_billing_ucxf_cf_piva;

One tip: if you are working with template files and you don't know which variables there are, you can print a list of variables in the template by using the PHP function get_defined_vars():

print '<pre>';
print_r(get_defined_vars());
print '</pre>';

This could lead to a long and unreadable page, but if you have the Devel module installed you can get the list of variables in a nice and readable markup this way:

if (has_krumo()) {
  krumo(get_defined_vars());
}

Similar issue in the Ubercart Addresses issue queue:
#1666144: Include extra fields on the invoice templates for ubercart

It seems I forgot to clearly document this somewhere. I'll leave this issue open until I have updated the README and the on-line documentation (of Ubercart Addresses).

mandreato’s picture

@MegaChriz it worked like a charm. Thank you very much !
It should be documented somewere indeed.

jawi’s picture

YEP! Worked for me :)

megachriz’s picture

Component: Code » Documentation

I have added a documentation page on drupal.org:
Displaying extra fields in invoice template

I still need to update the README.

megachriz’s picture

Status: Active » Fixed

I have updated the README-files for the 7.x-1.x and 6.x-2.x versions. I also cleaned up the README-files a little and updated some information that was a little bit outdated.

Commits:

DanZ’s picture

Status: Fixed » Active

The README and community docs do not adequately address modifying invoice template files for U3/D7.

The README wants you to just edit the file, which is a bad idea, because you'll lose your modifications when Ubercart gets updated. The community docs are just wrong.

There is a doc explaining the technique for U3/D7 at http://drupal.org/node/1867700. I recommend linking to that. I don't know much about doing it for U2/D6.

megachriz’s picture

@DanZ
By the sounds of it, the Extra Fields Pane documentation has two problems:

  1. It does not encourage the best practices.
  2. It implies the invoice template in Ubercart must be edited directly.

I made use of the following documentation when I first needed to customize the Ubercart invoice template:
Changing invoice templates for Ubercart 2.3 and later
There it is stated that if you want to edit the invoice, the template should be copied to your theme:

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.

The documentation page you are referring to (http://drupal.org/node/1867700) may also not be completely right. That implies that you need to rename the template once it is copied to the theme folder, while just leave the name as is also works (and then it would become "sites/all/themes/yourtheme/templates/uc-order--customer.tpl.php"). Implementing the hook hook_uc_invoice_templates() is only needed when the site needs different types of invoice templates. I think that for most webshops, a single invoice template for the customer is enough.

I agree that in the first paragraph of Extra Fields Pane's documentation about displaying extra fields in invoice templates, it is not clearly stated that the template should be copied and that it could let people to think that they need to edit the template in the Ubercart folder directly.
Later in the documentation, it is mentioned that the invoice template need to be copied to a theme, but that piece may be overlooked easily. While I think it's already known to themers that they should copy templates to their theme if they want to edit one, it could be good to mention this extra in the first paragraph of the documentation.

So, to sum things up, the only change that is needed is that it should be mentioned in the first paragraph of the documentation that the invoice template should be copied to a theme before editing it.
Agreed?

DanZ’s picture

So, to sum things up, the only change that is needed is that it should be mentioned in the first paragraph of the documentation that the invoice template should be copied to a theme before editing it.
Agreed?

I'm pretty sure that with U3, the template has to be copied to (themedirectory)/templates.

Whatever technique is in the documentation should be tested. I know http://drupal.org/node/1867700 works. Anything else...I have no idea. Better test it.

megachriz’s picture

@DanZ

I'm pretty sure that with U3, the template has to be copied to (themedirectory)/templates.

I did a test with the core theme 'Bartik' and the uc-order--customer.tpl.php template is also picked up when you just put it in the theme directory itself (but also when putting it into the templates subfolder). It could be that some themes not support that, not sure.

While http://drupal.org/node/1867700 probably also works (not tested), I think it is still easier to only copy the uc-order--customer.tpl.php to the theme folder if you only need one customer invoice template.

megachriz’s picture

Status: Active » Fixed

I've updated the documentation page to clarify the original invoice template should not be edited, but copied to a theme instead.

I've also updated the text in the README-files:

DanZ’s picture

FYI:

I have tested it myself, and it does indeed work to simply copy the customer invoice template file to the root of the theme directory and modify the copy there...so long as you don't change the name.

I updated http://drupal.org/node/1867700 to reflect this result.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.