First off, thank you for addressing one of the most glaring shortcomings of Drupal Commerce.

However, to quote Wikipedia, "A receipt is a written acknowledgment that a specified article or sum of money has been received as an exchange for goods or services. The receipt is evidence of purchase of the property or service obtained in the exchange." (emphasis added) The documents generated by this module are invoices, not receipts, because they provide no indication of whether or not the invoice has already been paid. As a first stab toward making the payment info available in the template, we can add the following lines to _commerce_invoice_receipt_get_invoice_info():

  $info['payment_method'] = $order->data['payment_method'];
  $info['status'] = $order->status;

  $payments = commerce_payment_transaction_load_multiple(NULL, array('order_id' => $order->order_number));
  if (is_array($payments)) {
    foreach($payments as $payment) {
      $info['payments'] .= $payment->message .'<br />';
    }
  }

Thank you for your consideration.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

budda’s picture

$payment->message doesn't appear to be suitable for displaying on an invoice. For the Sagepay module it includes transaction hash codes and other info which a customer doesn't need to see. Don't know about other international payment gateways.

BernieCram’s picture

An old issue I know, but I have addressed this issue in my site and perhaps this may be helpful others.

The order balance is stored in the payment transaction not in the order so you need to pull the order balance in from the payment transaction.

This can be done using hook_preprocess_commerce_order_invoice_view. The code in your template.php file will be something like this:

function MYTHEME_preprocess_commerce_order_invoice_view(&$vars) { 

        // Get the order object and the balance.
        $order = $vars['order'];
        $balance = commerce_payment_order_balance($order);
        $balance_round = round($balance['amount']/100, 2);
        $balance_formatted = sprintf("%01.2f", $balance_round);
               
        // declare the vars for use in the tpl file
        $vars['balance'] = $balance;
        $vars['balance_formatted'] = $balance_formatted;
       }

Here I am pulling in the balance array and formatting the raw 'amount' to show in a dollars and cents format. I can also use the currency code later.

Then you will need to print your new vars in the copy of commerce-order-invoice-view.tpl.php in your theme wherever you need it. It will look something like this:

  <table>
        <tr>
          <td><b><?php print t('Order Balance'); ?></b> </td>
          <td align="right"><?php print $balance_formatted; ?>&nbsp;<?php print $balance['currency_code']; ?></td>
        </tr>
    </table>

Hope this does something for you.

Cheers
Bernie

Daglees’s picture

Status: Active » Needs work
brephraim’s picture

@Bernie: Is there a reason for that function to go in the theme rather than in the module?

BernieCram’s picture

just that if you add a function to a module and forget that you have done it then update the module, it will overwrite your function and you won't have it any more.

B

Daglees’s picture

@BernieCram

Can you provide a patch?

http://drupal.org/patch/create

Horroshow’s picture

Tried #2 but it gave a warning message: Notice: Undefined variable: balance_formatted in include() (line 99 of /sites/all/modules/commerce_invoice_receipt/theme/commerce-order-invoice-view.tpl.php).

rbrownell’s picture

I too am looking for this feature. Though the solution in #2 works it is not complete in my mind. In order to properly indicate payment you must be able to show how the payment(s) were made and also be able accommodate multiple payment types in a kind of "Payment Line Items" fashion that would appear below the order total followed by a balance.

ShaneOnABike’s picture

Actually I think this also raises bigger issues around including other fields added as well. Why not just include the entire order rather then building a special array of handpicked fields?

Edit: Meaning include the entire order within the variables sent to the template.

meecect’s picture

In our case, we would only need to include something like:

PAYMENT INFORMATION
Card Type: VISA
Last 4 Digits (1111)

This helps consumers and customer support staff track down and reconcile orders when needed and seems to be a standard convention on emailed receipts/invoices

MrPeanut’s picture

Issue summary: View changes

I would agree that email receipts are the largest downfall of Drupal Commerce. I'm attempting to get a nice email receipt with Commerce Message, this module, and Commerce Email.

I tried the code from #1 but now I get "No line items found." and still no payment information.

meecect’s picture

I'm still not sending the payment info in the email, but I had a similar issue with the order completion checkout pane. There, I was able to use this snippet to get payment info:

<?php
if(arg(0) == 'checkout' && ctype_digit(arg(1)) && arg(2) == 'complete'){
	$body = '';
       
	$order = commerce_order_load(arg(1));
	$ow = entity_metadata_wrapper('commerce_order', $order);
	$body .= '<h4>Payment Information</h4>';
	if($order->data['tomy_payment']){
		$body .= 'Card Type: '.strtoupper($order->data['tomy_payment']['credit_card']['type']).'<br />';
		$body .= 'Last 4 Digits ('.substr($order->data['tomy_payment']['credit_card']['number'],-4,4).')';
	}
	print $body;
}
?>
Horroshow’s picture

Hi meecect,

Where did you put your code? In the template.php, in the module or in the commerce-order-invoice-view.tpl.php theme template?

Thanks!

meecect’s picture

In my case it was just for the the order summary screen, so it was in the rules action. Something could likely be adapted in one of the templates or views footers.

meecect’s picture

Sorry, I mean I put in my checkout page config:

/admin/commerce/config/checkout/form/pane/checkout_completion_message

the full code was this:

Thank you for your order <strong>[commerce-order:order-number]</strong>. Please print and save this page. You will receive an order confirmation email with this order summary and will need to reference the Order Number for all future inquiries. If you have not already done so, you may choose to activate an account to check the status of your order and make your future ordering easier. Look for the separate email with the activation information.


<h3 style="border-bottom: solid 1px;">Order Summary</h3>

<h4>Delivery Information</h4>

[commerce-order:commerce_customer_shipping]


<h4>Billing Information</h4>
[commerce-order:commerce_customer_billing]

<h4>Order Details</h4>
[commerce-order:commerce_line_items]

[commerce-order:commerce_order_total]

<?php
if(arg(0) == 'checkout' && ctype_digit(arg(1)) && arg(2) == 'complete'){
	$body = '';
       
	$order = commerce_order_load(arg(1));
	$ow = entity_metadata_wrapper('commerce_order', $order);
	$body .= '<h4>Payment Information</h4>';
	if($order->data['your_payment_type']){
		$body .= 'Card Type: '.strtoupper($order->data['your_payment_type']['credit_card']['type']).'<br />';
		$body .= 'Last 4 Digits ('.substr($order->data['your_payment_type']['credit_card']['number'],-4,4).')';
	}
	print $body;
}
?>
Horroshow’s picture

Hi meecect, thanks for the code. Is there a way to implement it in the commerce-order-invoice-view.tpl.php template from the Invoice Receipt module? I'm looking to show the card type and the last 4 digits of the card. Thanks!

/sites/all/modules/commerce_invoice_receipt/theme/commerce-order-invoice-view.tpl.php

thermalmusic’s picture

I agree that the invoice receipt must have payment and balance info included to indicate 'payment received'.
I tried adding BenStallings code to _commerce_invoice_receipt_get_invoice_info() but no luck yet. Can you please elaborate on this and how the variables can be placed in the template?

Thanks

meecect’s picture

I'll try to take a look at this today and see how I could adapt my snippet to put the info in the email/print invoice template. No guarantees though, I can go live on my site without it, but it is a nice to have.

echoz’s picture

I'd like to get the Payment method and the Balance (or Result message) in the commerce-order-invoice-view.tpl, and I couldn't get #2 to output anything.
This module is too good to abandon.

Anonymous’s picture

I'm going to roll a patch for this, looks like I need it in one of my projects. If you don't see a patch from me within the next few days feel free to ping to see if we actually proceeded with it.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
3.48 KB
74.12 KB

Here is a patch for the 7.x-1.x dev branch!

It adds payments, the site_name variable, and replaces the footer text with a variable_get (so please, feel free to create an admin page with a textarea for this). The variable is called "commerce_invoice_receipt_footer".

Screenshot of invoice using the patch.

Anonymous’s picture

This version of the patch will work with the 7.x-1.1 release.

echoz’s picture

Hi Ryan,
I was excited to see your work on this, since I'm trying to get help to get payment data into the tpl.

I would think that any committed development would be on the 7.x-2.x branch (I also didn't test because I'm using 7.x-2.x, having just starting with this module).

From what you've shown, I'll be trying to output the balance, and/or the Result message, whatever it takes to show if the order is paid. Help getting me there will be greatly appreciated!

echoz’s picture

With a combination of the code in the OP and from your patch, I can get the payment message, but get an error (goes away on reload) "Notice: Undefined index: payments" upon going back to the individual order screen after viewing the template via the print subtab. @Ryan Weal, are you getting this error?

echoz’s picture

I'm not going to change Category + Status but this is a support request thrown in as I try to solve this for my needs, major apologies if inappropriate here.

I'm testing in the module file itself for now, since I can't get any output in a custom module.

All is working as I want but I can't get rid of the error "Notice: Undefined index: payments" from the line in the .module file where I have "$info['payments']"

The error could hide initially, but will show loading another page, and is gone on reload.

In function _commerce_invoice_receipt_get_invoice_info
I've first added to the $info array -

'payment_method' => $order->data['payment_method'],

then added:

$payments = commerce_payment_transaction_load_multiple(NULL, array('order_id' => $order->order_number));

if (is_array($payments) && (sizeof($payments) > 0)) {
  foreach($payments as $payment) {
    $info['payments'] .= $payment->message .'<br />';
  }
}

I get the payment result message properly where I put in the tpl:

print isset($info['payments']) ? $info['payments'] : '';

Giving me either:
"Payment completed successfully." or "This order is waiting for the cheque to be cashed."

Can anyone *please* give me a hint to fix the "Undefined index: payments" error, occurring on the line beginning with - $info['payments'] ?

I researched it needs isset. Syntax help hugely appreciated!

rclemings’s picture

Ryan Weal: What payment system are you using with the patch in #22?

I'm using Commerce Cybersource SASOP for credit cards and the payload is structured altogether differently. All of the variables are blank when they get to the template. Same for Commerce Purchase Order and Commerce Cheque.

I'm using your patch as a starting point for my own but am wondering if there's not a more flexible solution to be had.

BD3’s picture

Tried the patch in #22 and it isn't working for Payflow Pro nor PayPal payments. Would be nice to have it work for any payment type as a lot of stores have multiple payment types.

meecect’s picture

I think in general it may be hard to solve this problem for everyone, as I'm not sure the payment info we are looking for is kept in a single unchanging data structure independent of the payment method. In my case, the payment info is in $order->data['my_payment_type'], but that's because I put it there, in a custom cybersource payment module customization that I wrote.

The existing cybersource module, for instance, did not support tokenization, so when I added that support, I made sure to add the original (but sanitized) card info to $order->data.

See, if I had not done that, then the card info would be a 21 digit token, not a card number, and I would have lost the last 4 digits.

But I think, (could be wrong) that each payment method picks and chooses what data it stores in the transaction message, so you will need to do a lot of 'print_r' or 'dpm()'s to figure out what you have access to and when.

In the template, you have access to the order_id, so you can always load up the whole order, and any transactions associated with and inspect all those data structures to find where your particular payment module is storing this info.

Remember, some payment methods don't even collect credit card numbers at all, so it wouldn't make sense for there to be a universal field or data array that would have this info, which is why each payment processing module handles it differently.

Echoz, try doing a print_r($order) in one of those steps and see what you get. Or, since you are loading the transactions, do a print_r($payments) to see what is available. If the payment info isn't in there, you will have to put it in at a different step of the process.

rclemings, I'm using a heavily modified version of commerce_cybersource, and in one of those functions where the card is being processed, I do this:

        // Put some card info into the order data for later extraction.
        // Note: the actual card number does not go here, only the profileID or token returned from the gateway
        $order->data['card_info'] = array(
          'number' => $response->paySubscriptionCreateReply->subscriptionID,
          'exp_month' => $pane_values['credit_card']['exp_month'],
          'exp_year' => $pane_values['credit_card']['exp_year'],
          'card_type' =>  _commerce_cybersource_card_type($pane_values['credit_card']['number'], TRUE),
          'last_4' => substr($pane_values['credit_card']['number'], -4)
        );

WHERE you put that code is going to be specific to SASOP, and I'm not familiar enough with that module to help.

In my case it is in commerce_cybersource_soap_cc_submit_form_submit, so the main submit handler that attempts to do the transaction. It is probably possible to also do it in a custom module that hooks on or does a form alter on the checkout form, so you can grab the data before it is deleted.

Keep in mind, that many of these modules have an explicit goal of not storing ANY credit card info at all, not even the last 4 digits. They are simply taking the submitted info and returning a transaction succesful message. Some module will record some basic info of the payment method when doing this, but it is not required.

tj99ay’s picture

I've installed this module and the patch from #22, and for testing I am using a payment method of "Cheque", but I am getting the following error:

Notice: Undefined index: payments in _commerce_invoice_receipt_get_invoice_info() (line 254 of /etc/drupal/7/sites/all/modules/commerce_invoice_receipt/commerce_invoice_receipt.module).

I am hoping the reason for the error is simply because I have not supplied card details as intended by the patch.

What would be required to display any other payment method, such as Cheque, COD, Cash, Paypal etc?

It's so close to a fab module to sort out invoicing requirements :-)

capfive’s picture

FileSize
63.08 KB
73.73 KB

I got excited when i saw this, but i hope we can figure out a solution.

Can i ask why we need to display the credit card what was used? Should just the payment method and amount, showing that there is nothing owing be sufficient?

I have altered the order view to show the payment information, but am now just trying to get it to display in commerce invoice receipt, this will be a whole other problem, because people need permission to see payments, which means they can see any payment, there is no option to only view your own payments.

So if we can build a view that will show the info that we desire is there a way we can just print this in the template? excuse my simplistic view on the situation (pun intended) but what I have done is altered the line item view with the following:

payment info

1. Added the relationships for the order ID then the payment transation, which gives access to the payment information.

2. Inserted the correct fields to show the amount, payment method, successful or unsuccessful payment message, date and also the amount owing still, then exclude all these so they don't show up in the table

3a. Add the global text field and make sure you tick "Use replacement tokens from the first row" then insert the tokens as you see fit, here is the code i used

3b. here is the code and the result (i tried to make it email friendly)

payment info

<h4>Payments</h4>
<table width="400" style="width:400px !important" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row">
 <tr>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    <strong>Status:</strong>
  </td>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    [message]
  </td>
</tr>
<tr>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    <strong>Payment Method:</strong>
  </td>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    [payment_method] 
  </td>
</tr>
<tr>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    <strong>Payment Date:</strong>
  </td>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    [created]
  </td>
</tr>
<tr>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    <strong>Total Amount Paid:</strong>
  </td>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    [amount]
  </td>
</tr>
<tr>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    <strong>Balance Owing:</strong>
  </td>
  <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150">
    [balance]
  </td>
</tr>
</table>

I hope this turns into a usable solution some how :P

aramboyajyan’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Needs work

Changing the status and branch this is related to. Current work is being added to the 7.x-2.x branch, so we would need a patch against it instead.

Can't promise anything, but if I do get some time to look into this, I'll port the patch myself.

Thanks everyone!

fibie’s picture

Hi everyone

has anyone got a working version?

Been trying to figure this out for hours and not getting anywhere and tried all the suggestions above

#30 looks like what I need but I think I am missing something

I would like to show

Status
Payment Method
Payment Date
Amount Paid
Balance

I am using the 7.x-1.1 release

capfive’s picture

would you like me to give you my views export?

fibie’s picture

Thanks capfive it would be worth a try

Did you alter the existing line item view or clone it and call the new view something else?

I tried altering the existing one the line items didn't show up anymore

Not sure what I am doing wrong.

Thanks for your help

capfive’s picture

edited the original

$view = new view();
$view->name = 'commerce_line_item_table';
$view->description = 'Display a set of line items in a table.';
$view->tag = 'commerce';
$view->base_table = 'commerce_line_item';
$view->human_name = 'Line items';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'line_item_id' => 'line_item_id',
  'type' => 'type',
  'line_item_title' => 'line_item_title',
  'line_item_label' => 'line_item_title',
  'commerce_unit_price' => 'commerce_unit_price',
  'quantity' => 'quantity',
  'commerce_total' => 'commerce_total',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'line_item_id' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'type' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'line_item_title' => array(
    'align' => '',
    'separator' => ' ',
  ),
  'line_item_label' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'commerce_unit_price' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'quantity' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'commerce_total' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => 'views-align-right',
    'separator' => '',
  ),
);
/* Footer: Global: Text area */
$handler->display->display_options['footer']['area']['id'] = 'area';
$handler->display->display_options['footer']['area']['table'] = 'views';
$handler->display->display_options['footer']['area']['field'] = 'area';
$handler->display->display_options['footer']['area']['content'] = '<h4>Payments</h4>
<table width="600" style="width:600px !important" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row">
       <tr>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150"><strong>Status:</strong></td>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:250">[message]</td>
      </tr>
       <tr>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150"><strong>Payment Method:</strong></td>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:250">[payment_method]</td>
      </tr>
       <tr>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150"><strong>Payment Date:</strong></td>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:250">[created]</td>
      </tr>
       <tr>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150"><strong>Total Amount Paid:</strong></td>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:250">[amount]</td>
      </tr>
       <tr>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:150"><strong>Balance Owing:</strong></td>
        <td class="col" valign="top" style="font-family:Helvetica, Arial, sans-serif;font-size:14px;line-height:10px;text-align:left;color:#333333;width:250">[balance]</td>
      </tr>
    </table>';
$handler->display->display_options['footer']['area']['format'] = 'full_html';
$handler->display->display_options['footer']['area']['tokenize'] = TRUE;
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['label'] = 'Empty line item text.';
$handler->display->display_options['empty']['area']['content'] = 'No line items found.';
$handler->display->display_options['empty']['area']['format'] = 'plain_text';
/* Relationship: Commerce Line Item: Order ID */
$handler->display->display_options['relationships']['order_id']['id'] = 'order_id';
$handler->display->display_options['relationships']['order_id']['table'] = 'commerce_line_item';
$handler->display->display_options['relationships']['order_id']['field'] = 'order_id';
/* Relationship: Commerce Order: Payment Transaction */
$handler->display->display_options['relationships']['payment_transaction']['id'] = 'payment_transaction';
$handler->display->display_options['relationships']['payment_transaction']['table'] = 'commerce_order';
$handler->display->display_options['relationships']['payment_transaction']['field'] = 'payment_transaction';
$handler->display->display_options['relationships']['payment_transaction']['relationship'] = 'order_id';
/* Field: Commerce Line Item: Line item ID */
$handler->display->display_options['fields']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['fields']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_id']['field'] = 'line_item_id';
$handler->display->display_options['fields']['line_item_id']['label'] = 'ID';
$handler->display->display_options['fields']['line_item_id']['exclude'] = TRUE;
/* Field: Commerce Line Item: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['type']['field'] = 'type';
$handler->display->display_options['fields']['type']['exclude'] = TRUE;
/* Field: Commerce Line Item: Title */
$handler->display->display_options['fields']['line_item_title']['id'] = 'line_item_title';
$handler->display->display_options['fields']['line_item_title']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_title']['field'] = 'line_item_title';
/* Field: Commerce Line Item: Label */
$handler->display->display_options['fields']['line_item_label']['id'] = 'line_item_label';
$handler->display->display_options['fields']['line_item_label']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_label']['field'] = 'line_item_label';
$handler->display->display_options['fields']['line_item_label']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['line_item_label']['alter']['text'] = '([line_item_label])';
/* Field: Commerce Line item: Unit price */
$handler->display->display_options['fields']['commerce_unit_price']['id'] = 'commerce_unit_price';
$handler->display->display_options['fields']['commerce_unit_price']['table'] = 'field_data_commerce_unit_price';
$handler->display->display_options['fields']['commerce_unit_price']['field'] = 'commerce_unit_price';
$handler->display->display_options['fields']['commerce_unit_price']['click_sort_column'] = 'amount';
/* Field: Commerce Line Item: Quantity */
$handler->display->display_options['fields']['quantity']['id'] = 'quantity';
$handler->display->display_options['fields']['quantity']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['quantity']['field'] = 'quantity';
$handler->display->display_options['fields']['quantity']['precision'] = '0';
/* Field: Commerce Line item: Total */
$handler->display->display_options['fields']['commerce_total']['id'] = 'commerce_total';
$handler->display->display_options['fields']['commerce_total']['table'] = 'field_data_commerce_total';
$handler->display->display_options['fields']['commerce_total']['field'] = 'commerce_total';
$handler->display->display_options['fields']['commerce_total']['click_sort_column'] = 'amount';
/* Field: Commerce Payment Transaction: Amount */
$handler->display->display_options['fields']['amount']['id'] = 'amount';
$handler->display->display_options['fields']['amount']['table'] = 'commerce_payment_transaction';
$handler->display->display_options['fields']['amount']['field'] = 'amount';
$handler->display->display_options['fields']['amount']['relationship'] = 'payment_transaction';
$handler->display->display_options['fields']['amount']['label'] = '';
$handler->display->display_options['fields']['amount']['exclude'] = TRUE;
$handler->display->display_options['fields']['amount']['element_label_colon'] = FALSE;
/* Field: Commerce Payment Transaction: Payment method */
$handler->display->display_options['fields']['payment_method']['id'] = 'payment_method';
$handler->display->display_options['fields']['payment_method']['table'] = 'commerce_payment_transaction';
$handler->display->display_options['fields']['payment_method']['field'] = 'payment_method';
$handler->display->display_options['fields']['payment_method']['relationship'] = 'payment_transaction';
$handler->display->display_options['fields']['payment_method']['label'] = '';
$handler->display->display_options['fields']['payment_method']['exclude'] = TRUE;
$handler->display->display_options['fields']['payment_method']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['payment_method']['title'] = 'short_title';
/* Field: Commerce Payment Transaction: Message */
$handler->display->display_options['fields']['message']['id'] = 'message';
$handler->display->display_options['fields']['message']['table'] = 'commerce_payment_transaction';
$handler->display->display_options['fields']['message']['field'] = 'message';
$handler->display->display_options['fields']['message']['relationship'] = 'payment_transaction';
$handler->display->display_options['fields']['message']['label'] = '';
$handler->display->display_options['fields']['message']['exclude'] = TRUE;
$handler->display->display_options['fields']['message']['element_label_colon'] = FALSE;
/* Field: Commerce Order: Order Balance */
$handler->display->display_options['fields']['balance']['id'] = 'balance';
$handler->display->display_options['fields']['balance']['table'] = 'commerce_order';
$handler->display->display_options['fields']['balance']['field'] = 'balance';
$handler->display->display_options['fields']['balance']['relationship'] = 'order_id';
$handler->display->display_options['fields']['balance']['label'] = '';
$handler->display->display_options['fields']['balance']['exclude'] = TRUE;
$handler->display->display_options['fields']['balance']['element_label_colon'] = FALSE;
/* Field: Commerce Payment Transaction: Created date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'commerce_payment_transaction';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['relationship'] = 'payment_transaction';
$handler->display->display_options['fields']['created']['label'] = '';
$handler->display->display_options['fields']['created']['exclude'] = TRUE;
$handler->display->display_options['fields']['created']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['created']['alter']['text'] = '[created]';
$handler->display->display_options['fields']['created']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['created']['date_format'] = 'long';
$handler->display->display_options['fields']['created']['second_date_format'] = 'long';
/* Sort criterion: Commerce Line Item: Line item ID */
$handler->display->display_options['sorts']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['sorts']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['sorts']['line_item_id']['field'] = 'line_item_id';
/* Contextual filter: Commerce Line Item: Line item ID */
$handler->display->display_options['arguments']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['arguments']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['arguments']['line_item_id']['field'] = 'line_item_id';
$handler->display->display_options['arguments']['line_item_id']['default_action'] = 'empty';
$handler->display->display_options['arguments']['line_item_id']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['line_item_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['line_item_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['line_item_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['line_item_id']['break_phrase'] = TRUE;

I cant remember if I did anything in the line item display area... sorry it was awhile ago!

fibie’s picture

That has helped thanks. I see better now what you had and copied it straight in with no issues

Did you ever get the global text area to show up in the receipt?

I am still not seeing the payment information and it all looks right to me.

Have I missed something that should also go in to the tpl?

capfive’s picture

FileSize
96.21 KB

oh yes! I did some large customisation to the commerce-order-invoice-view.tpl.php file, but most of it was styling and putting shipping address etc.

I dont think I did any editing to what was printed.

I just confirmed i did not

Maybe I changed something in the product line item display settings? (in admin/commerce/config/line-items/product/display)

See my screenshot and compare

Product Display Field

fibie’s picture

capfive I owe you a beer (:-)

In case anyone needs this - It needs to be the default line item view called commerce_line_item_table for it to work. I had imported your view but views had renamed it because the original was still there. I had disabled the original in case I needed to refer to it. Once I modified the original exactly as you had it and enabled it again it worked perfectly. Don't know why I didn't think of that before.

Thanks a million

fibie’s picture

Further to capfive's solution I found that the payment information was causing the line items to be duplicated if there was more than one transaction applied to the order. What happens in this case is that the payment info shown is from the first transaction in the list. Eg if the user had aborted their payment and tried again so the first transaction failed.

To resolve this I added the Views Distinct module and applied aggregation repeats Views Distinct settings to all the payment fields. Then applied filter repeats to the Commerce Line Item: Title (Title) field.

I ended up removing the total amount paid field as it was showing the total from the first (failed) transaction and I didn't really need it to be showing anyway. Then changed the date format on the created date field so that it showed the date minus the time stamp to avoid confusion.

It seems to work, if any one has a better solution let me know.

capfive’s picture

very smart!

I guess that beer is bought and paid for now! ;)

I think this solution should be part of the view as standard/

fibie’s picture

Ha yeah took me a while to figure it out couldn't have done it without your initial help though (:-)

mgadrat’s picture

Here's another approach to display the payments in the receipt. Maybe a little bit simpler.

First, create a view of payments that take the Order ID as an argument.

Next create a custom module that hooks into the pre-process of the receipt:

/**
 * Implements hook_preprocess_commerce_order_invoice_view).
 */
function MY_MODULE_preprocess_commerce_order_invoice_view(&$variables) {
  
  // Embed the view passing the order_number as an argument
  $variables['info']['payments'] =  commerce_embed_view('MY_CUSTOM_VIEW', 'defaults', array($variables['info']['order_number']));
}

Then copy this template file in your theme's folder:
/sites/all/modules/commerce_invoice_receipt/theme/commerce-order-invoice-view.tpl.php

Now wherever you want in the template file, just echo the $info['payments] variable.

  echo $info['payments'];
rsbecker’s picture

A way to avoid the duplication of line items may be to create an attachment display that comes after the default. Put the relations and the order-total, amount, balance, payment-method and transaction created fields in the attachment display. Exclude them from the display and create a global tact area in the footer. Put the table for those fields in the footer because that gives you more control over positioning ( you can wrap it in a div that has float: right). You must have one visible field in the attachment display, so add a custom text field in which you place  , and make that the first field.

BTW, if you have the entity_view_modes module enabled, you can go to order config>manage display, you can choose which view to display. You don't have to use the line items table default display.

Daglees’s picture

Status: Needs work » Patch (to be ported)