Upon order completion there is a rule that sends out an email. There are some order specific variables listed under Replacement Patterns that you can add to the email body. Such as [order:order-id]. I need to add in other order details not listed in the Replacement Patters. Such as line items, Billing Name, etc. Is this possible?

Can anyone help me?

I see that the fields that are there are there because of modules/order/commerce_order.tokens.inc but I can figure out how to add in these others.

Thank you!

Comments

maestrojed’s picture

I case someone else is looking to do this, I was about to accomplish this with the php filter and using $order, commerce_customer_profile_load(), commerce_line_item_load_multiple(), and commerce_line_item_title().

But I do believe this data should be tokens that appear as replacement patterns.

Jed

switch13’s picture

I am looking to do this as well. In particular the line items. subscribe

gioris’s picture

+1

amfis’s picture

There is a sandbox module: http://drupal.org/sandbox/paul.linney/1252292

With this I was able to craft my custom order email using theme template from this module.

vasike’s picture

subscribe. i also think there should be a better support for the notifications capabilities.
what about payment for this?

loko’s picture

kpv’s picture

thx maestrojed

cameron prince’s picture

You can create your own replacement patterns using the following example code. Note that $order contains all the order data. Use the devel module's dpm() to view the contents of $order and then format and return the data as desired.

/**
* Implements hook_token_info_alter().
*/
function MYMODULE_token_info_alter(&$info) {
  $info['tokens']['commerce-order']['custom-token'] = array(
    'name' => t('Custom token'),
    'description' => t('My custom commerce-order token.'),
  );
}

/**
* Implements hook_tokens().
*/
function MYMODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {

  $url_options = array('absolute' => TRUE);

  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
    $language_code = $options['language']->language;
  }
  else {
    $language_code = NULL;
  }

  $sanitize = !empty($options['sanitize']);

  $replacements = array();

  if ($type == 'commerce-order' && !empty($data['commerce-order'])) {
    $order = $data['commerce-order'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'custom-token':
          $replacements[$original] = 'MY OUTPUT';
          break;

      }
    }
  }

  return $replacements;
}
bojanz’s picture

Component: Order » Contributed modules
Status: Active » Fixed

Commerce Message now provides a powerful solution.

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

Marko B’s picture

Issue summary: View changes

Think bojanz was aiming at https://www.drupal.org/project/commerce_email not commerce message.

bojanz’s picture

No, I wasn't.

Marko B’s picture

yes sorry, just looked more into messages and I guess you were aiming at summary part of that module. So there are more ways to tackle this problem.
I apologize :)