Drupal commerce order notification to field in a line item type I have a Drupal 7 install using Drupal Commerce to handle donations. I created a line item type called donations, with fields such as donation amount, anonymous donation, etc.

One field of the donation line item type is called honoree email, which is an optional email field that when filled out is suppose to sends the donation order to the user who created it and the honoree.

In order to send the email to the honoree, I wanted to add a new action to the "Send an order notification e-mail" rule and use data selection to highlight the honoree email field in the "To" value. However, I am unable to find the honoree field. My data selector looks like this:

commerce-order:commerce-line-items:...


and I'm presented with an array 0-3;
commerce-order:commerce-line-items:0:
commerce-order:commerce-line-items:1:
commerce-order:commerce-line-items:2:
commerce-order:commerce-line-items:3:

I'm not sure what the differences are, and the values under each of those keys do not include the custom fields the I added to the donation line item.

How do I access the honoree email field?
What you've encountered here is how Rules deals with multi-value fields. The commerce-line-items field is a multi-value line item reference field using "delta" values represented by those 0, 1, 2, 3, etc. numbers. Without knowing the full details of your situation, the best I can recommend is to add a loop over that commerce-line-items field, passing each line item to a Rules component designed to e-mail the honoree.

If you aren't familiar with Rules components, that's certainly more than we can get into here. Your best bet would be to find the Rules Mastery course on YouTube and get your learnin' on.

Once you have the idea, what you'll need is a Rule component that accepts a Commerce Line Item as a parameter. It should have at least these two conditions:


Entity has field - does the line item have your honoree e-mail field?
Data value is empty (negated) - does the honoree e-mail field have a value?


If so, your actions section can send the necessary e-mail using the value of that field as the e-mail recipient.