I am trying to fetch the author of products found in an order to alert them they have a new order to confirm. I am trying to use rules to create new content or send them an email. I have my current attached rules export here to view. Right now i am just trying to create a new basic node to test the concept of grabbing the product's author.
{ "rules_notify_tour_operator" : {
"LABEL" : "Notify Author",
"PLUGIN" : "reaction rule",
"TAGS" : [ "Orders" ],
"REQUIRES" : [ "rules", "entity" ],
"ON" : [ "commerce_order_insert" ],
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "commerce_product" } }
],
"DO" : [
{ "entity_fetch" : {
"USING" : { "type" : "commerce_product", "id" : [ "commerce-order:order-id" ] },
"PROVIDE" : { "entity_fetched" : { "fetched_product" : "Fetched Product" } }
}
},
{ "entity_fetch" : {
"USING" : { "type" : "user", "id" : [ "fetched-product:creator:uid" ] },
"PROVIDE" : { "entity_fetched" : { "fetched_author" : "Fetched Author" } }
}
},
{ "entity_create" : {
"USING" : {
"type" : "node",
"param_type" : "page",
"param_title" : "Test Message",
"param_author" : [ "fetched-author" ]
},
"PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
}
},
{ "entity_save" : { "data" : [ "entity-created" ] } }
]
}
}
So far no luck any help would be greatly appreciated.
Comments
Comment #1
rszrama commentedThis sounds like a perfect question for http://www.drupalcommerce.org/questions. If you repost it there and provide a link in this issue, I'll be happy to come propose a solution.
Comment #2
xbrianx commentedI originally was going to post in the answers section, you can find the re-post here: http://www.drupalcommerce.org/questions/8897/how-do-i-fetch-product-auth...
But then I saw how little responses questions got and thought I might get more traction in the drupal.org forums.
Comment #3
clevername commentedI just did something similar with a custom function. This assumes there is only one product author for all items in the cart and only takes the uid from the first product in the array.
Comment #4
krystlc commentedThis took me a while to figure out so I'll post my solution. Too many steps, so I'll just dump these rules for you to use at your own risk.
As explained here http://www.drupalcommerce.org/questions/8897/how-do-i-fetch-product-auth... you'll need to create a new rule component and then loop it with the line item list in your new checkout rule.
Create a new rule component admin/config/workflow/rules/components and import this rule.
Secondly, create your new checkout rule here admin/commerce/config/checkout/rules with this:
Note: disregard that second data comparison in the rule component.
Comment #5
jOksanen commentedTo fetch only the first product (which was perfect in my case, you can use a simpler rule).
Comment #6
nellngun commentedHi krystlc, trying to make it work... What do u mean by Note: disregard that second data comparison in the rule component? I import both rules with no results.
Comment #7
nellngun commentedHi still me, do you know how to fetch all product infrormation (all fields)?