Now I get emails saying 'Array' for items Name, Street and City. Stopped working after updating the module.
This is my template:
Purchase date: [commerce-order:placed]
Contact details:
Email: [commerce-order:mail]
Phone: [commerce-order:commerce-customer-billing:commerce_customer_address:phone-number]
Billing:
Name: [commerce-order:commerce-customer-billing:commerce-customer-address:name-line]
Phone: [commerce-order:commerce-customer-billing:commerce_customer_address:phone-number]
Street: [commerce-order:commerce-customer-billing:commerce-customer-address:thoroughfare]
City: [commerce-order:commerce-customer-billing:commerce-customer-address:locality]
State: [commerce-order:commerce-customer-billing:commerce-customer-address:administrative_area]
ZIP: [commerce-order:commerce-customer-billing:commerce-customer-address:postal_code]
Shipping:
Name: [commerce-order:commerce-customer-shipping:commerce-customer-address:name-line]
Phone: [commerce-order:commerce-customer-shipping:commerce_customer_address:phone-number]
Street: [commerce-order:commerce-customer-shipping:commerce-customer-address:thoroughfare]
City: [commerce-order:commerce-customer-shipping:commerce-customer-address:locality]
State: [commerce-order:commerce-customer-shipping:commerce-customer-address:administrative_area]
ZIP: [commerce-order:commerce-customer-shipping:commerce-customer-address:postal_code]
<table width="100%">
<tbody>
<tr>
<td colspan="2">[commerce-order:commerce_extra_tokens_order_line_items]</td>
</tr>
<tr>
<td>[commerce-order:commerce_extra_tokens_order_total]</td>
</tr>
</tbody>
</table>| Comment | File | Size | Author |
|---|---|---|---|
| #18 | interdiff_15-18.txt | 2.68 KB | jsacksick |
| #18 | addressfield-field-tokens-3013566-18.patch | 8.23 KB | jsacksick |
| #15 | addressfield-fix-tokens-without-token-module-3013566-15.patch | 5.49 KB | jsacksick |
| #8 | addressfield-3013566-tokens_broken-8.patch | 797 bytes | czigor |
Comments
Comment #2
juves commentedI am having the same issue.
Comment #3
rszrama commentedIt should be safe to revert while we debug.
Comment #4
rszrama commentedCan y'all confirm that you are not using the Token module on your sites? Also, can you confirm that reverting to 1.2 fixes the issue? The only relevant change that comes to mind is #2416997: Statically cache the list of address fields during token generation.
Comment #5
matas.k commentedYou can use tokens without Token module? I'm using Token, Commerce Extra Tokens and Entity Tokens.
Comment #6
bojanz commentedComment #7
matas.k commentedYes, I can confirm that downgrading back to 7.x-1.2 works as supposed.
But then upgrading back to 1.3 also now works.
Before the downgrade there was some token error for rules module spitting out, but I don't remember what it was and I deleted the log, sorry. I don't know if it's 1.3 related.
But now it's working so I don't get it.
Reproduce:
1. Upgrade from 1.2 to 1.3 on production site with drush 'pm-update'
2. Tokens don't print on email for Name, Street, City.
3. Downgrade back to 1.2 (by removing the addressfield dir and unzipping old 1.3)
4. drush updatedb/clear caches and it works, correct Tokens printed.
5. Upgrade back to 1.3 with pm-update and now it also works.
6. ???
I'm testing checkout emails by triggering 'Simulate checkout completion' at e.g. admin/commerce/orders/51/edit
Comment #8
czigor commentedThis fixes the issue for me and also makes the change in #2416997: Statically cache the list of address fields during token generation a smaller one.
Comment #9
jsacksick commentedHm... that's weird, In that case, there's no need for the loop
foreach (array($field_name, strtr($field_name, '_', '-')) as $name) {, but did you do some tests with / without the token module?In the end, we still alter the
$data['tokens'][$group][$name]array although we check for the $field_name key...Comment #10
matas.k commentedIsn't token module required by Entity Tokens and Commerce Extra Tokens? How do you print tokens to email without token module?
Comment #11
jsacksick commented@vibrasphere: Can you check if the token module is enabled on your install?
Comment #12
matas.k commentedYes, it's enabled. Like I said it prints all tokens fine except for fields Name, Street and City. I tried this already on multiple sites.
Comment #13
jsacksick commentedSo you're having issues with the token name that has dashes? ([commerce-order:commerce-customer-billing:commerce-customer-address:name-line]).
Because I'm trying that and it works for me... But it actually doesn't when the token module is disabled.
Comment #14
matas.k commentedThe template I posted is working with 1.2, but not 1.3.
1.3 gives 'Array' for Name, Street and City, while all other fields and tokens work fine. And they also have dashes.
Anyway, like I said, when you upgrade to 1.3 from 1.2 and then downgrade back to 1.2 and upgrade back to 1.3 it is fixed. At least that's what I got in one site.
Comment #15
jsacksick commentedI did several tests and here are my findings:
Without the code in addressfield_token_info_alter(), printing the token
[commerce-order:commerce-customer-billing:commerce-customer-address:name-line](with dashes) returns "Array".With the code, if the "token" module is enabled, both
[commerce-order:commerce-customer-billing:commerce-customer-address:name-line]and[commerce-order:commerce-customer-billing:commerce_customer_address:name-line]work.However, in the current state, printing
[commerce-order:commerce-customer-billing:commerce-customer-address:name-line]when the token module isn't enabled doesn't return anything, the reason for that is that we change the token type from "struct" to "address-field".If we keep the type to "struct", the "entity_token" module is actually in charge fo the token replacement...
So we actually have two options:
The attached patch is making sure the token replacement is performed by the Addressfield module, both when the token module is enabled / disabled.
@vibrasphere: Could you apply the attached patch, clear caches and make sure it works for you?
Comment #16
matas.k commentedIt stopped showing State and Zip.
Comment #17
jsacksick commentedYeah, the reason for that is that you're using administrative_area and not administrative-area (if you want the state code you can use administrative-area-raw).
Same with the zip, you're using "postal_code" instead of "postal-code".
Basically, when Addressfield doesn't alter the token type to "address-field", when it's "struct", the token is handled by the "entity_token" module.
With the patch, Addressfield is handling the tokens for both "commerce-customer-address" and "commerce_customer_address" but the field name (postal-code, etc.) always has dashes....
We could probably expand the patch to support both "-" and "_" for addressfield field names, but I'm not sure that's the way to go.
Comment #18
jsacksick commented@vibrasphere: Could you test now with the attached patch? It should now both support postal-code and postal_code.
I don't really understand all those inconsistencies... but well... Since many people are probably printing both, let's support both.
Comment #19
matas.k commentedYes, it's working now.
Comment #20
xaa commentedthank you for the explanation.
I think this will ensure that existing project won't break.
ps Here I don't use entity_token neither addressfield_tokens
Comment #21
tyler-durden commentedI'm having the same issue with this latest update, however this patch doesn't seem to solve the issue.
I am using Entity Tokens also, and have cleared the cache multiple times.
Comment #22
jsacksick commented@tyler-durden: Could you describe exactly what's not working for you? Which tokens are you trying to print etc? That'd allow us to replicate the issue.
Comment #23
tyler-durden commentedI reapplied the patch and it seems to be working now. I must have done something wrong with the initial patch update.
Comment #24
xaa commented@Tyler are you sure you have only reapply the patch?
The patch was working for me but not anymore.
I try to use the following tokens on Metatag user og description:
a[node:field_addresse:country]
b[node:field-addresse:country]
c[node:field_addresse:country-code]
d[node:field-addresse:country-code]
no results.
same issue with locality.
Comment #25
waverate commentedPatch #18 applied cleanly against 7.x-1.3 and re-enabled the tokens.
Thank you @jsacksick.
Comment #27
bojanz commentedCommitted #18. Thanks, everyone!
Comment #28
egarbeil commentedChanging the underscores to hyphens throughout fixed the problem for us - with token module installed. 7.66, all modules current.
Comment #30
heyyo commentedI still have another issue with this. The tokens are correctly displayed within devel token in any node, but printed empty in the node's metatags.
It seems to be an language error related. I have the module locale enabled, with only english language.
to fix my issue I replaced in function addressfield_tokens
with
Comment #31
anybodyThis is definitely not fixed!
With 7.x-1.2 tokens are working correctly in metatags, in 7.x-1.x-dev and latest stable release 7.x-1.3 they are broken. I'm for example using:
in a single value field which outputs the correct value testing with 7.x-1.2 and outputting NOTHING in metatags with latest 1.3 and dev.
There are several follow-up issues, I'll reply there if one of the patches fixed the problem for me. But this should definitely be fixed with a new stable release.
Follow-Ups / related see:
Thank you!
Comment #32
anybodyReverting back to 7.x-1.2 now, because I couldn't find a solution... The other issues seem unrelated in my case.
Comment #33
vaccinemedia commented@anybody I can confirm that downgrading from 1.3 to 1.2 fixed the issue regarding tokens being output in metatags. Specifically I'm adding job posting schema to a jobs section on a website and need each part of the address to be output as the components of the address in the schema json. I'm not using any custom code, I'm using the schema metatag module.
During testing on version 1.3 of this module I took a look at the token display of the job content type and noticed it was in the disabled region. I thought that this may have been the cause of the missing tokens (always check the token display!). I enabled it and saw SEVERAL options for outputting as either default, individual components separated by a delimiter, just the country name etc... I selected default. Still nothing. Selected the other options, nothing.
I then downgraded to 1.2 and found that using the hyphenated tokens e.g. [node:field-address:thoroughfare] worked for the components of the address:
Unfortunately [node:field-address:country-code] does not work (it did for a brief second but not now). So:
1.2 has a single option for the token display and works and 1.3 has several options for the token display and doesn't work with metatag.
Comment #34
Manovra76 commentedworkaround for token
file addressfield.token.inc:
1) apply patch #18
2) add this code in line 132 in function addressfield_tokens
[...]
$sanitize = !empty($options['sanitize']);
+ if($type=='address-field') {
+ if(!isset($data['address-field'][$language_code])) {
+ $language_code = LANGUAGE_NONE;
+ }
+ }
$replacements = array();
Comment #35
lwalley commentedNew issue created for the incorrect language code see #3082673: Language code incorrect in token replacement.
Comment #36
jeff.a commentedThe code in #34 using 7.x-1.3 seems to have fixed my issue with metatags. Added it to line 116, not 132.
Patch #18 fails for me. Also, I haven't had issues with pathauto tokens, only metatag.
Comment #37
ciss commentedUnfortunately the changes in this issue effectively cripple token replacement via the entity module, without offering a proper replacement (pun intended), especially in multi-language environments. Imo it should be reevaluated to what extent addressfield is even responsible for replacing tokens.
A short refresher on how field tokens get replaced:
I'd argue that addressfield should at the very least leave any dash tokens alone, and only try to handle underscore tokens.