1

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?

1 Answer 1

1

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:

  1. Entity has field - does the line item have your honoree e-mail field?
  2. 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.

2
  • 1
    Thanks, Ryan, for all your contributions to the Drupal community and this quick reply! After adding the two conditions, I was able to access the particular field I needed. I did this for delta 0, then exported the rule, changed the delta value for 1, 2, and 3, and imported into new rules. Perhaps there is a cleaner way of implementing a loop over the line-items, but this worked.
    – Evil E
    Feb 12, 2013 at 20:41
  • Kudos for experimentation. Glad you got it working. If you wanted to try it, you can click the "Add loop" link beside "Add action" to give the loop a shot. You'll basically then just nest actions beneath that loop. Oh! Lucky day! Just searched and found that the video on Rules loops is freely available on Drupalize.me: drupalize.me/videos/lists-and-loops Feb 13, 2013 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.