Hi,

Just wondering if there is a way to either use difference templates when emailing an invoice via rules, or alternatively make some elements of an invoice conditional based on who the invoice is going to.

In my scenario upon placing an order an email gets sent to the customer, with full invoice and a short thank you note above it in the email, a copy of the invoice also goes to the accounts department, and one to the warehouse to handle dispatch. It would be great if I could customise what gets sent to each.

I noticed in function commerce_invoice_receipt_mail there is a switch on $key with a single case ('invoice'), and wondered if that was the beginnings of handling multiple cases.

Cheers,
Sam

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mstrelan’s picture

I believe this exists in Ubercart, or it at least existed when I last used it in Drupal 6. Would be great to have this in Commerce. I believe it would be as simple as:

  • Duplicate, rename and modify the .tpl.php
  • Reference the new template in commerce_invoice_receipt_theme()
  • Modify commerce_invoice_receipt_rules_action_info(). Add an option to choose the template to use.
  • Modify commerce_invoice_receipt_action_mail() to detect which template was chosen. Include that as the second argument to drupal_mail(), eg invoice_admin.
  • Modify commerce_invoice_receipt_mail() to invoke the new theme hook.

In that time I could have written a patch ...

mstrelan’s picture

Here's a first attempt at a patch. Currently if you override the template file in your theme directory you would need to override both template files. Should be easy to fix in the hook_theme() implementation. Also, I was previously able to put my template in a subdirectory of my theme but now I cannot for some reason. Have not really looked in to that.

aramboyajyan’s picture

Status: Active » Postponed (maintainer needs more info)

Could you please create a patch against the latest dev branch? Thanks!

jlockhart’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Component: Miscellaneous » Code
Status: Postponed (maintainer needs more info) » Needs review
FileSize
25.13 KB

This was exactly what we were looking for. I've rerolled the patch to work with 7.x-2.x-dev and I updated the find the templates code so that it searches for both the customer and admin templates in the front end theme. I have my templates within /templates and its picking them both up.

Thanks.

joel_osc’s picture

Status: Needs review » Needs work

Thanks @jlockhart for the nice work on the patch, we need this functionality as well. I did notice the patch in #4 breaks my site because function commerce_invoice_receipt_rules_action_info() is now declared twice.

Error: Cannot redeclare commerce_invoice_receipt_rules_action_info() (previously declared in
/var/www/html/mysite/sites/all/modules/contrib/commerce_invoice_receipt/commerce_invoice_receipt.module:302) in
/var/www/html/mysite/sites/all/modules/contrib/commerce_invoice_receipt/commerce_invoice_receipt.rules.inc, line 100

I think the code added to commerce_invoice_receipt.module needs to be moved to commerce_invoice_receipt.rules.inc.