With the orientation on rules standards for token replacement related modules are broken e.g. commerce_email and commerce_invoice_email.
There is now a lot of work to get these modules together again especially with documentation in all related modules.
Related issues:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lathan’s picture

It looks like the patch that went into this module #1682730: Use standard rules token evaluation was dependant on the patch to rules #1547160: Support variable substitution in direct input mode which was rejected in-favour of #812058: add token support for non-entities basically putting back the changes from the path #1682730: Use standard rules token evaluation makes this function once again.

lathan’s picture

FileSize
3.01 KB

Here is a patch that does this.

lathan’s picture

Status: Active » Needs review
FileSize
3.07 KB

Small fix missing include.

Summit’s picture

Hi,
Is this patch also needed when you use Alpha1? It seems that Alpha1 is recommended to get Tokens instead of Token placeholders..
EDIT I think it is not needed for Aplha1, but for commerce-order:commerce-customer-billing it is not working, still only shows placeholder...
greetings, Martijn

ShaneOnABike’s picture

Component: Documentation » Code

CONFIRMED this totally works and has literally saved me. Please apply this patch! No tokens were being applied properly until I applied this patch (it works in the correct languages too)

@Summit: Yes this is still a huge problem in Alpha1. I had it all working before but then it stopped working again which was super confusing for me.

@jucallme - THANKS so much this is totally saved the hair that remains on my head (half ripped out in wondering what the heck was going on)

PS - You had this set to documentation I changed it to code

akalata’s picture

This patch got most of the required tokens working again (after #34 at #1559844: Field token is not replaced when fields are blank recommended upgrading from alpha1 to dev), but not the optional field tokens -- leaving me back where I started, but at least fixing the issue introduced by #1682730: Use standard rules token evaluation.

kevster’s picture

@summit - this patch worked for me when applied to the dev version. I did try the other method of using message + mesage notify etc but still couldnt get the address tokens working and had HTML issues so reverted back to variable email + commerce email.

@akalata - this may fix your blank issue if you havent found a fix already?

@shaneonabike - using the dev introduced the blank field issue but adding this (taken from https://drupal.org/node/1559844 #34):

// Remove tokens if no replacement value is found. As token_replace() does
// if 'clear' is set.
$replacements += array_fill_keys($tokens, '');

(apologies I havent learnt patching yet...)

after line 132 of variable_email.rules.inc (dev version) then fixes the blank tokens so doesnt print out the token name.

so you end up with:

else {
      $replacements += token_generate($var_name, $tokens, array(), $options);
    }
    + // Remove tokens if no replacement value is found. As token_replace() does
    + // if 'clear' is set.
    + $replacements += array_fill_keys($tokens, '');
  }

This one has been driving me round the bend, Ive spent at least two days trying various module versions, patches and hacks. I still cant use the address tokens:

[commerce-order:commerce-customer-billing:commerce-customer-address] or
[commerce-order:commerce-customer-billing:commerce_customer_address]

[commerce-order:commerce-customer-shipping:commerce-customer-address] or
[commerce-order:commerce-customer-shipping:commerce_customer_address]

so have ended up having to pull in individual tokens e.g.

SHIP TO:

[commerce-order:commerce-customer-shipping:commerce-customer-address:name_line]
[commerce-order:commerce-customer-shipping:commerce-customer-address:first_name] [commerce-order:commerce-customer-shipping:commerce-customer-address:last_name]
[commerce-order:commerce-customer-shipping:commerce-customer-address:organisation_name]
[commerce-order:commerce-customer-shipping:commerce-customer-address:thoroughfare]
[commerce-order:commerce-customer-shipping:commerce-customer-address:administrative_area]
[commerce-order:commerce-customer-shipping:commerce-customer-address:locality]
[commerce-order:commerce-customer-shipping:commerce-customer-address:sub_locality], [commerce-order:commerce-customer-shipping:commerce-customer-address:postal_code]
[commerce-order:commerce-customer-shipping:commerce-customer-address:country]

but at least im getting tokens in the order email and blanks where no data...

lmeurs’s picture

#3 so far works for me. This patch brings back code that was removed from the 7.x-1.0-alpha1 version (#1682730: Use standard rules token evaluation).

The patch probably needs another adjustment:

foreach (token_scan($text) as $var_name => $tokens) {

should become:

foreach (token_scan($whole_text) as $var_name => $tokens) {
Danny Englander’s picture

I just applied the patch from #3 to the latest dev and am now getting this error resulting in a WSOD on the front end of my site:

Error: parse error in /sites/all/modules/contrib/variable_email/variable_email.rules.inc, line 147

As far as I can tell the patch applied cleanly. The odd part is line 147 in the patched file is simply a blank line.

bradjones1’s picture

FileSize
3.23 KB

Here's a patch which fixes the WSOD (missing } at end of file) as well as incorporates feedback from #8 and #7. Re-rolled against -dev and seems to work for me with token and rules -dev versions.

xurizaemon’s picture

Status: Needs review » Needs work

The following two patches appear to reverse each other?

@highrockmedia, the patch in #3 here is missing a final }. With that, you'd revert back to Variable Email with edb34a89 removed.

I'm using that currently, but I suspect the proper fix is to identify why the change in edb34a89 doesn't apply to some actions (because isset($element->settings['variable:process']) is not set for the emails I'm sending).

I have to put this issue down now but hope to come back to it.

[EDIT: I see Brad was making patches while I was typing, nice one Brad!]

Frederic wbase’s picture

I can confirm that the path of bradjones in 10 is working like a charm, thanks for your work m8.
RTBC?

grts

Frederic

a.milkovsky’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

#10 works, thank you!

4kant’s picture

#10 is working.
Thanks!

drifter’s picture

Also confirming that applying #10 makes tokens resolve again. Please commit.

GiorgosK’s picture

#10 solves tokens not replaced
please commit its already tested and reviewed by many

mr.york’s picture

FileSize
3.15 KB

Reroll the patch.

geek-merlin’s picture

Denes.Szabo’s picture

Re-rolled the patch to apply from the module's directory.