I set up a Rule with event "Order state is updated - per order line", and in the action I use uc_order tokens and uc_line_item tokens. This works fine for anonymous checkout if Pathauto is disabled. But if pathauto is enabled, then the uc_order and uc_line_item tokens don't replace at all for anonymous checkouts.

HOW TO REPLICATE
- Install Drupal 6
- Download ubercart, token, uc_rules, rules, pathauto
- Enable Ubercart core required modules, plus token, uc_rules, rules and rules ui
- Create a new Product with any name, sku, and sell price
- Create a new rule with event Order State is updated - per order line, and any action where you can use uc_line_item or uc_order tokens, such as "Adds a comment to the order"
- Test anonymous checkout, token replacement works
- Enable pathauto and test anonymous checkout again, token replacement breaks
- Disable pathauto and test anonymous checkout again, token replacement works again

Comments

ericbroder’s picture

At first I thought the data was being lost somehow, but when I run through my php debugger I can see the data is available, it's just not being accessed properly for some reason. I was able to hack token.module to just force the token replacement:

function token_replace_multiple($text, $types = array('global' => NULL), $leading = TOKEN_PREFIX, $trailing = TOKEN_SUFFIX, $options = array(), $flush = FALSE) {

...

  // return str_replace($tokens, $full->values, $text);
  $newtext = str_replace($tokens, $full->values, $text);
  // Hard code token replacements that are not working for anonymous user checkout.
  if ($type == 'uc_line_item') {
    if (strpos($newtext, '[uc_line_item:uc_line_item_order_id]')) {
      $newtext = str_replace('[uc_line_item:uc_line_item_order_id]', $types['uc_line_item']->order_id, $newtext);
    }
    if (strpos($newtext, '[uc_line_item:uc_line_item_price]')) {
      $newtext = str_replace('[uc_line_item:uc_line_item_price]', $types['uc_line_item']->price, $newtext);
    }
    if (strpos($newtext, '[uc_line_item:uc_line_item_qty]')) {
      $newtext = str_replace('[uc_line_item:uc_line_item_qty]', $types['uc_line_item']->qty, $newtext);
    }
  }
  return $newtext;
}

And I don't know if this is related but I also got really weird results in my php debugger, like false readings on variable values, such as arrays that show up with only 30 keys but really have a lot more keys. I was trying to analyze this part of the above function:

  foreach ($types as $type => $object) {
    $temp = token_get_values($type, $object, $flush, $options);
    $full->tokens = array_merge($full->tokens, $temp->tokens);
    $full->values = array_merge($full->values, $temp->values);
  }

  // Support clearing out tokens that would not be replaced.
  if (!empty($options['clear'])) {
    foreach ($text_tokens as $token) {
      if (!in_array($token, $full->tokens)) {
        $full->tokens[] = $token;
        $full->values[] = '';
      }
    }
  }

  $tokens = token_prepare_tokens($full->tokens, $leading, $trailing);

Any ideas?

owen barton’s picture

Just reporting that I was able to reproduce this - haven't figured out a cause yet. I did notice that the issue is resolved (for me) when clean_urls is disabled, so it is appears perhaps broader than pathauto. I have confirmed that the uc_rules_token_values() return value is the same regardless of the clean_url setting.

m.stenta’s picture

I am also experiencing this. Looking for a fix now...

m.stenta’s picture

Status: Active » Closed (duplicate)

Ok, I figured this out. It's actually a duplicate of this issue: #1234052: Token hooks should not be in Rules include file, so I'm marking this as a duplicate.

I posted a patch to that issue that solves the problem for me.