Part 1: About the concept of using Replacement tokens
By using the Rules module, you should be able to make any relevant token concerning the order details content
(as in your question ...) available by using the Replacement patterns for each message type created with the Message module.
So the answer to your question is "Whatever token you're missing, just make it available via Rules, by creating a replacement token for them". Refer to the answer to What's the purpose of "Replacement tokens" of a Message type? for way more details on that.
These Replacement tokens are really a hidden gem about how Rules integrates with Message. For an example to see them at work, refer to my answer to "Which user related token(s) can be used to create a Rule for setting up a message type?".
Part 2: Including some order detail in your message type
1. Scenario
Let's assume you want allow the user to enter some (custom) order detail. I.e. let's just call it "order remark" (some free format text, which any customer can use for whatever they want).
We want the related order confirmation message (actually an eMail) to have an eMail subject that includes the value of the free format text entered as "order remark".
Read on for the steps needed to get this to work ... Starting from a vanilla "Commerce Kickstart" installation.
2. Add an additional order field
Use relative path admin/commerce/config/order/fields
to add another (custom) field within "Order settings". In my case, I use a text field, with machine name field_order_remark
.
3. Define a replacement token
Use relative path admin/structure/messages/manage/commerce_order_order_confirmation
to edit the configuration of Message type "Commerce Order: order confirmation". Within the field labelled "Replacement tokens", enter something similar to @remark_related_to_order
(= this will be the name of the token we want to use / populate in the next step).
On the same (Message type) form, you can start to use (= refer to) this replacement token, and this anywhere you want to do so. As a sample, I just added (remark: @remark_related_to_order)
at the end of the eMail subject (within the Message Text labelled "View modes: Notify - Email subject").
4. Custom rule
The only thing left, is to create an appropriate rule (or tune an existing rule), so that when a Message is created (of type "Commerce Order: order confirmation"), a value is assigned to the replacement token @remark_related_to_order
, whereas the actual value is the value entered for the (custom) order field with machine name field_order_remark
.
To do so, just consider the rule below (in Rules export format):
{ "rules_commerce_order_message_order_notification" : {
"LABEL" : "Commerce order message: order notification e-mail",
"PLUGIN" : "reaction rule",
"WEIGHT" : "3",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "message_notify", "commerce_checkout" ],
"ON" : { "commerce_checkout_complete" : [] },
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "field_order_remark" } }
],
"DO" : [
{ "entity_create" : {
"USING" : {
"type" : "message",
"param_type" : "commerce_order_order_confirmation",
"param_user" : [ "commerce-order:owner" ]
},
"PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
}
},
{ "data_set" : {
"data" : [ "entity-created:message-commerce-order" ],
"value" : [ "commerce-order" ]
}
},
{ "data_set" : {
"data" : [ "entity-created:arguments:remark-related-to-order" ],
"value" : [ "commerce-order:field-order-remark" ]
}
},
{ "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } },
{ "message_notify_process" : {
"message" : [ "entity-created" ],
"save_on_fail" : 0,
"save_on_success" : 0
}
}
]
}
}
The above rule is actually a minor variation of the same named rule shipped with Commerce Kickstart, in which these are the specific changes I applied to get it to work:
- the extra Rules Condition "Entity has field". This is to make rules aware of the (custom) order field with machine name
field_order_remark
. And so that we can refer to it in a subsequent Rules Action.
- the extra Rules Action to "Set a data value". I.e. for the replacement token
remark_related_to_order
, whereas the actual value is the value entered for the (custom) order field with machine name field_order_remark
. Note the special syntax used for that entity-created:arguments:remark-related-to-order
Voilà, that's really it. Just repeat the steps above for any other "order detail" you want to be processed in a similar way (each of them will require an additional replacement token, and the rule will have to assign an appropriate value using some order related token.
PS: I'm assuming your question is about D7.