good to have this module, but i want to send more types of messages.

message types should be addable via the ui.
and possible to send them via rules.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agf1583’s picture

Bump.

It would be very useful to have multiple templates, then be able to choose which template to use when setting up the rule.

zmove’s picture

Subscribe

jsheffers’s picture

This is imperative. I want to send two separate emails depending on what product types are in the cart.

TaraRowell’s picture

You can extend the template types via code...
I believe you must have these dependencies in your .info file:

dependencies[] = variable_email
dependencies[] = commerce_email

<?php
/**
 * Implements hook_variable_info().
 */
function MYMODULE_variable_info($options) {
 
  $variable['commerce_email_custom_name_[mail_part]'] = array(
    'title' => t('Title of my template'),
    'type' => 'mail_html',
    'description' => t('Description of my template'),
    'children' => array(
      'commerce_email_custom_name_subject' => array(
        'default' => 'Text that can contain tokens like [commerce-order:order-number] and [site:name]',
      ),
      'commerce_email_custom_name_body' => array(
        'default' => '<p>Thank you for your recent order [commerce-order:order-number] blah blah blah................</p>'
      ),
    ),
    'group' => 'commerce_email',
  );
  return $variable;
}  
?>
TravisJohnston’s picture

Issue summary: View changes

Hello Tara,

Thank you. Just to be clear, is the [mail_part] and MYMODULE the only sections that need to be changed, or does custom_name also need to be changed to something else?

TaraRowell’s picture

Hi Travis,

Yes - you can make as many extra templates as you want but changing custom_name to whatever you want to name your template.

Actually, I'm not sure you even have to edit the [mail_part] text. I think it will display as HTML in the UI - you'll just have to experiment.

TravisJohnston’s picture

Awesome, Thanks Tara! Worked like a charm!

Summit’s picture

Hi Travis,
May be good to also place your email template here, so people can copy-paste your work?
Thanks in advance if you are willing to.
greetings, Martijn

TravisJohnston’s picture

Sure thing.

So I have the need to have a separate email template for orders that contain regular products versus registration products since they will contain different information in the body. I have custom module called "ces_custom" and this code was placed into it's .module file.

/**
 * Implements hook_variable_info().
 */
function ces_custom_variable_info($options) {
  $variable['commerce_email_product_admin_[mail_part]'] = array(
    'title' => t('Admin Product Email'),
    'type' => 'mail_html',
    'description' => t('Admin email for Product orders'),
    'children' => array(
      'commerce_email_product_admin_subject' => array(
        'default' => 'Order #[commerce-order:order-number] from [site:name]',
      ),
      'commerce_email_product_admin_body' => array(
        'default' => '<p>email body text here</p>'
      ),
    ),
    'group' => 'commerce_email',
  );
  $variable['commerce_email_product_user_[mail_part]'] = array(
    'title' => t('User Product Email'),
    'type' => 'mail_html',
    'description' => t('User email for Product orders'),
    'children' => array(
      'commerce_email_product_user_subject' => array(
        'default' => 'Thank you for your recent order at [site:name]',
      ),
      'commerce_email_product_user_body' => array(
        'default' => '<p>email body text here</p>'
      ),
    ),
    'group' => 'commerce_email',
  );
  return $variable;
}

nelslynn’s picture

It would also be great if you could create a template with different line items, for example I'm trying to create a packing slip that does not include pricing or line item totals. There is a packing slip module, but it's not set up via a rule to be send automatically after order placement.

Any ideas how I go about this?

TravisJohnston’s picture

Hi nelslynn,

I found that a lot of the included tokens didn't include the proper information or the format that I wanted. I ended up using the Token Embed Views module instead. This allowed me to create a view display that displayed all the correct information I wanted and then embed the view results inside of the email body using a custom token.

SurajHo’s picture

Hi Travis,

I was curious about how you used Token Embed Views in Commerce Email. I have created a view that will use the order-id as an argument. When I use the token to call this view in the confirmation email, it works when I put in a particular order-id. But I don't know how to put the order-id that comes with the confirmation email. Just for fun I tried to use [views:embed:view-name:display-id:[commerce-order:order-id]] but that obviously did not work. Could you tell me how you used Token Embed Views?

Regards,

Suraj

TravisJohnston’s picture

Hey SurajHo,

I attached an image of the relations I use. I do not supply a specific order ID, but that probably wouldn't hurt. At the moment, my view pulls in the latest order information based on ID. Since the email is generated immediately, it snags the output of the view and embeds it in the email. This has worked great for me since it has yet (and hopefully never) to happen when 2 orders are completed at the exact same time.

Your approach sounds like a better way to remove any chance of a order id mixup, but I don't think it's working because the context filters aren't being passed back to the view in time.

SurajHo’s picture

Hi Travis,

Sorry for the late reply. I hadn't subscribed to this issue. Thanks for supplying your setup of the view. I'm going to try this out and see how it works. And indeed, hoping that completing 2 orders at the exact same time won't occur. I currently use PHP code in the e-mail with the PHP filter, which works great, but I'm not very fond of making the PHP filter available at all.

Gr,

Suraj

rszrama’s picture

Status: Active » Closed (outdated)