If the data about a product are not available when processing a "line item", you can make them available. To do so, use a technique similar to what is explained in my answer to "How to access commerce_product field of line-items using Rules to flag the Commerce Product?", which includes a Rules Component that looks like so:
{ "rules_perform_an_action_on_a_selected_line_item" : {
"LABEL" : "Perform an action on a selected line item",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "selected_line_item" : { "label" : "Selected Line Item", "type" : "commerce_line_item" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "selected-line-item" ], "field" : "commerce_product" } }
],
"DO" : [
{ "entity_fetch" : {
"USING" : {
"type" : "commerce_product",
"id" : [ "selected-line-item:commerce-product:product-id" ]
},
"PROVIDE" : { "entity_fetched" : { "product_fetched" : "Fetched Product" } }
}
},
{ "drupal_message" : { "message" : "Some details about this product: Product ID = [product-fetched:product-id], Product SKU = [product-fetched:sku], Product Title = [product-fetched:title], Product Creator = [product-fetched:creator]" } }
]
}
}
Here is a blueprint of what you need to do:
- Create a Rules Component, similar to the above Rules Component. Just an import of that Rules Component should be enough (to get started and further improve it as detailed below).
- Rework the Drupal Message shown via the last Rules Action in the Rules Component (Starting with "
Some details about this product
"), e.g. by also using any of the available tokens that fit your needs.
- Execute that Rules Component inside your Rules Loop of the rule in which you want to loop over all line items.
- Improve the Rules Component from Step 1 by creating whatever additional Rules Action(s) you need. Make sure to place these Rules Action(s) AFTER that Rules Action (in the Rules Component) that performs "Fetch entity by ID".