2

I'm having trouble sending order notification emails to anonymous users. As a bare-bones test I have created a new rule which triggers on 'Completing the checkout process', checks if the current user is authenticated, and if not sends an email to [commerce-order:mail]. When it's triggered I get the following error message, suggesting it is not able to get the email address from the order.

Error sending e-mail (from [email protected] to ).

I'm fairly sure the problem isn't to do with Rules config as it's so simple, but here is the export anyway:

{ "rules_anonymous_order_notification" : {
"LABEL" : "Anonymous Order Notification",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "Commerce Checkout" ],
"REQUIRES" : [ "rules", "commerce_checkout" ],
"ON" : { "commerce_checkout_complete" : [] },
"IF" : [
  { "NOT user_has_role" : {
      "account" : [ "site:current-user" ],
      "roles" : { "value" : { "2" : "2" } }
    }
  }
],
"DO" : [
  { "mail" : {
      "to" : [ "commerce-order:mail" ],
      "subject" : "Order received!",
      "message" : "This is to tell you the order has been received.",
      "language" : [ "commerce-order:state" ]
    }
  }
]

} }

What else could be causing this?

EDIT: I've just noticed in the db the mail column is empty for anonymous orders in 'commerce_order' - is this normal?

4
  • By default commerce order will use the mail associated with the user account.
    – James
    Jan 18, 2017 at 6:23
  • @james : what's the "user account" for an anonymous user (as in the question here)? Jan 18, 2017 at 8:36
  • @Pierre.Vriens, anonymous user won't be having any mail, that is why the commerce order also not having any mail. There is an option in commerce to allow the user to login while checkout. I believe the functionality works fine. I usually ask user to login before proceeding to checkout itself. So, I have never faced the above mentioned issue with commerce and rules.
    – James
    Jan 18, 2017 at 8:45
  • ... but have a look at this post where people reported success with using [commerce-order:mail] for anonymous users drupalcommerce.org/questions/8175/… - it makes me think that something is wrong with my installation
    – Chris
    Jan 18, 2017 at 10:09

2 Answers 2

1

Have a look at issue # 430274, about an event which is a variation of your event here, and somehow explains that "after saving something" actually happens ... "before saving something" (which is not a bug, simply how the Rules module works ...).

A possible compromise to avoid these kind of issues, is to transform what you're trying to do in your Rules Action in a Rules Component, so that your Rule "schedules the execution" (using the Rules Scheduler submodule) of that Rules Component. For example after only a few seconds or minutes later on (if your cron job runs frequent enough, otherwise it'll be next time cron runs). This compromise will ensure that, at the time the Rules Component is executed, the "Checkout process" for sure completed, and your "eMail ID" will have been updated as expected.

Rules debugging

If none of the above helps, then move on to Rules debugging, as explained in my answer to "How can I display the value of a variable inside a condition?".

Depending on what the result of that type of debugging is, you may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value" (in your case of your commerce-order:mail). It may help to check if the cause of your problem is because of what is written in the comments from james, i.e.:

anonymous user won't be having any mail, that is why the commerce order also not having any mail. There is an option in commerce to allow the user to login while checkout. I believe the functionality works fine. I usually ask user to login before proceeding to checkout itself. So, I have never faced the above mentioned issue with commerce and rules.

1

If the mail property for the order isn't being populated, it could be you have disabled the "Account information" checkout pane or allowed customers to bypass it somehow. (For example, an off-site payment method may not result in the mail being properly populated depending on how the payment gateway was integrated.)

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.