Hi. Here's my use case: I would like to send out an additional email to the customer when they purchase a specific set of products. I set the trigger to "order state is updated" so the uc_order object is in scope. I got the conditions setup correctly because the email only sends out when I want it to. And I've selected the "send an email to an arbitrary email address"

When I'm in the action, I'm given a list of tokens related for the Order, Old Order Status, and New Order status. However, when I add any of those tokens into the body field (notably [uc_order:uc_order_primary_email]), the token is not replaced.

I know the token system is working because if I add in [uc_order:store-email], it works.

To try and debug, I tried tracking the the uc_rules_token_values to try and watch the order object go through and populate the tokens, but it doesn't seem to get called.
dpm("DEBUG BELOW");
dpm($type);
dpm($object);

$object is either blank or :global.

So my question: is the user object simply not being passed in properly? Is there something faulty with the tokens presented? Do these tokens truly exist for the action I'm trying to send in?

Any help would be greatly appreciated!

Comments

rickmanelius’s picture

Status: Active » Fixed

This was weird. Somehow rules 6.x-1.4 was actually NOT fully upgraded and that's what caused the error. Using filemerge to compare differences led to the solution. Apologies for distracting, but I never would have thought to check that!

rickmanelius’s picture

Status: Fixed » Active

I spoke too soon. I reset and tried to start from scratch, and now it's not working again.

rickmanelius’s picture

Here is an update. When I switch the order from pending to complete, the order tokens are not available. But when you switch from complete to pending, the order tokens work.

I can't think why this would be the case... why would the order object depend on the target status and not be used in all circumstances.

heyyo’s picture

Seems it was a token bug resolved in token 6.x-1.18

http://drupal.org/node/1330722
http://drupal.org/node/1329196

rickmanelius’s picture

Status: Active » Needs review

Thanks. Setting to 'needs review' so I can do a quick test and confirm it's all good. If I don't get back to this in a week, anyone can feel free to close this.

heyyo’s picture

I still have this annoying bug, even by using the last version of token module.
Do you have any more luck on this ?

EKM’s picture

StatusFileSize
new521 bytes

I came across this bug a couple of days ago. It appears to be caused by the default load ordering of token, and rules modules causing token to fire before the inclusion of the uc_rules.rules.inc file, which includes the necessary uc_rules_token_values() file.

The attached fix forces the loading of uc_rules.rules.inc. A better long term fix would be to fix token_include() to do something like all $module.token.inc files across modules, and shift the uc_rules_token_list() and uc_rules_token_values() functions into a uc_rules.token.inc file.

Hope this helps!

m.stenta’s picture

Version: 6.x-1.0-rc1 » 6.x-1.x-dev
StatusFileSize
new10.97 KB

The Token hooks should not be in the uc_rules.rules.inc file in the first place. Attached is a patch that moves them into the uc_rules.module file.

Also, closing #1379132: Token replacement breaks for anonymous checkout when Pathauto is enabled. as a duplicate.

m.stenta’s picture

Title: Tokens not substituting despite listed as available during an email action » Token hooks should not be in Rules include file

Oops, meant to change the issue title, not the tags.

m.stenta’s picture

StatusFileSize
new10.99 KB

Updated patch to remove whitespace and fix the following PHP notice:

Notice: Undefined variable: tokens in uc_rules_token_values() (line 179 of .../uc_rules/uc_rules.module).
tinker’s picture

Status: Needs review » Closed (duplicate)

Whilst the patches provided here do fix the immediate issue they do not address the root cause which is that 'uc_order' rules data type is not defined. I have created a new issue which fixes the root problem, re-uses the tokens defined by UberCart, moves the remaining token 'uc_line_item tokens' to the module files, and fixes the undefined variable 'token': #2039405: Define uc_order rules data type, fixes tokens, add new order conditions conditions, split forms to new include file

Marking this as duplicate since it does not fix the root cause. Please review the patch provided in #2039405.