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