Have a look at the question about "How to access commerce_product field of line-items using Rules to flag the Commerce Product?". The accepted answer to it (disclosure: it's mine ...) explains how that question can be solved (also) by creating a Rules Component, and which 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]" } }
]
}
}
Note the parameters used in this Rules Component, i.e. selected_line_item
( = the line item being processed). And also note the type
of that parameter (a Commerce line item).
The main rule just executes this Rules Component, as part of a Rules Loop in it, whereas in each iteration of that loop the actual line item being processed is passed as the value for that parameter. So with this example in mind, it seems that this might be a solution to your questions:
How can I let rules know what kind of entity I'm looping through
The type of the parameter you pass to the Rules Component.
... so it will give me access to the custom fields on that entity
I think your Rules Component would not need any extra Rules Conditions, though if needed (as shown in my Rules Component example with the Rules Condition related to "Commerce Product"), you could add relevant other Rules Conditions if needed.
For the sake of completeness, some more details about that Rules Component:
- By adding the Rules Condition, I got access to the value of the id (key) of the Commerce Product that the line item was about.
- Since I had made the value of that id (key) of the Commerce Product avaiable, I could use the Rules Action to fetch an entity by id (entity being the Commerce Product). And by doing that, from then on I had ALL the data (fields) of the Commerce Product available.