0

As a follow up to previous questions asked by me: Send mail to product owner with Rules and Fetch Customer Profile from Line Items. I have the following question.

I created a rule to send an e-mail to the product owner of a product in my commerce webshop. The email address is added to the product by hand in a custom field. The rule is working when the email address is available but when not available it sends out an error. How can I check to see if the e-mail address is there and only then send the e-mail.

This is my rule:

{ "rules_svds_send_mail_to_product_owner" : {
"LABEL" : "SVDS: Send mail to product owner",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"OWNER" : "rules",
"TAGS" : [ "SVDS" ],
"REQUIRES" : [ "rules", "commerce_payment" ],
"ON" : { "commerce_payment_order_paid_in_full" : [] },
"DO" : [
  { "variable_add" : {
      "USING" : { "type" : "commerce_order", "value" : [ "commerce-order" ] },
      "PROVIDE" : { "variable_added" : { "commerce_order_value" : "Commerce Order" } }
    }
  },
  { "LOOP" : {
      "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
      "ITEM" : { "line_items" : "Commerce Line Items" },
      "DO" : [
        { "component_rules_perform_an_action_on_a_selected_line_item" : { "selected_line_item" : [ "line-items" ] } }
      ]
    }
  }
]
}
}

The component I use in the loop is like this:

{ "rules_perform_an_action_on_a_selected_line_item" : {
"LABEL" : "Perform an action on a selected line item",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "mimemail" ],
"USES VARIABLES" : {
  "selected_line_item" : { "label" : "Selected Line Item", "type" : "commerce_line_item" },
  "commerce_order" : { "label" : "Commerce Order", "type" : "commerce_order" }
},
"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" } }
    }
  },
  { "entity_fetch" : {
      "USING" : { "type" : "commerce_order", "id" : [ "commerce-order:order-id" ] },
      "PROVIDE" : { "entity_fetched" : { "fetched_customer" : "Fetched user" } }
    }
  },
  { "mimemail" : {
      "USING" : {
        "key" : "[commerce-order:order-id]",
        "to" : "[product-fetched:field-e-mailadres-product]",
        "subject" : "Product ordered",
        "body" : "E-mail body text",
        "language" : [ "" ]
      },
      "PROVIDE" : { "send_status" : { "send_status" : "Send status" } }
    }
  }
]
}}

Thanks in advance

1 Answer 1

0

The email address is added to the product by hand in a custom field

I supouse that the field for entering email, is an email field (must enter a 'valid email' in format: [email protected], avioding a 'blah blah email'), if so: then in your rule add a condition: [your_email_field] is not empy, if that condition is far away to be implemented in rules area: condition, then use rules conditional module, when your a ready to implement 'send email' in your rule, before that accion, add condition: [your_email_field] is not empty, if user entered a 'fake email', drupal will send email, but it will not go anywhare, this way you can avoid your error, and only valid emails will be delivered.

2
  • Thanks, I indeed wasn't able to get to the [your_email_field]. But installing a module to get this to work was a bit to much for me. I ended up making the [your_email_field] required.
    – Joost
    Commented Jan 5, 2019 at 18:31
  • if it was usefull my answer please up vote it, regards.
    – pinueve
    Commented Jan 5, 2019 at 18:45

Your Answer

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

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