I've added some custom fields to customer billing, and I'm using tokens for those in the checkout completion message and in notification emails. For non-required fields, if the customer leaves the field empty, the token itself is output, ie "[commerce-order:commerce-customer-billing:field-foo]". Not ideal.

I guess the "clear" option isn't being passed when replacing these field tokens, and I'd like to fix this. For starters I'm trying to figure out where the token replacement happens - in a commerce module, or is core field module responsible?

#2 clear_tokens_with_no_values-1665060-2.patch733 bytesvasike
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


John Pitcairn’s picture

OK, for the completion message it's commerce_checkout.checkout_pane.inc, line 143:

// Perform token replacement.
$message = token_replace($message, array('commerce-order' => $order));

A change to:

// Perform token replacement.
$message = token_replace($message, array('commerce-order' => $order), array('clear' => TRUE));

Will prevent the empty token placeholder from being rendered. But this will also change behavior if anyone was relying on the empty token placeholder for anything.

vasike’s picture

Status: Active » Needs review
733 bytes
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es). View

and here the patch for John Pitcairn solution.
Thank you Sir.

joshmiller’s picture

Status: Needs review » Reviewed & tested by the community

Bug confirmed; Patch applied cleanly; Bug fixed.

Note: Should you try and figure this bug out using rules as opposed to using the checkout completion, you'll find that Rules' implementation of token_replace() also has this flag that is missing. That is, if you use a [token], it doesn't silently remove it from the "send mail" or "system message" actions. That is another patch and another module completely.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Alrighty, added the clear as patched.

brephraim’s picture

Status: Fixed » Needs work

I'm still getting this in my order confirmation messages after the patch has been applied: [message:message-commerce-order:commerce-customer-shipping:commerce_customer_address]

rszrama’s picture

Status: Needs work » Fixed

I used your precise token on a site that doesn't even have Shipping installed, and I do not see the token in the checkout completion screen. That said, you should note that joshmiller's comment above explains that we could only fix this for our checkout pane's message and not other messages or e-mails generated by Rules. Rules would have to be patched for that.

joshmiller’s picture

Status: Fixed » Closed (fixed)

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