Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Rules integration
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 Jan 2012 at 13:00 UTC
Updated:
19 Feb 2012 at 22:00 UTC
{ "rules_update_product_display_for_existing_commerce_product" : {
"LABEL" : "Update Product Display for existing Commerce Product",
"PLUGIN" : "reaction rule",
"TAGS" : [ "commerce" ],
"REQUIRES" : [ "rules", "entity" ],
"ON" : [ "commerce_product_update" ],
"DO" : [
{ "entity_query" : {
"USING" : {
"type" : "node",
"property" : "field_product",
"value" : [ "commerce-product:product-id" ]
},
"PROVIDE" : { "entity_fetched" : { "product_display" : "Fetched entity" } }
}
},
{ "data_set" : {
"data" : [ "product-display:0:title" ],
"value" : [ "commerce-product:title" ]
}
},
{ "data_set" : {
"data" : [ "product-display:0:author" ],
"value" : [ "commerce-product:creator" ]
}
},
{ "entity_save" : { "data" : [ "product-display:0" ] } }
]
}
}i want to update a field in product display node by updating related product.
but in rules i can't acces to custom fields.
i have read this: http://www.drupalcommerce.org/faq/rules-field-data-selection but there are not entity type "product display" to set in conditions.
any advice?
thanks.
Comments
Comment #1
rszrama commentedYeah, there is no direct connection from the product to its display, because theoretically it can be referenced from any number of sources. However, if you know you have a one product -> one node setup, then you can use the Rules action to "Fetch entity by property" to load a node referencing your product so long as you know the name of the field used to reference the product from the node. Then you can update it to your heart's content. : )
Comment #2
dgastudio commentedthank u for your help.
Editing action set "Commerce products update" (action set becouse i want to use it in VBO)
add action:
Fetch entity by property
Entity type: node
Property: product (reference link in product display)
Value: product:product-id
Limit result count: 10
Save
Add a new action
Data selector: entity-fetched:0 (1,2,3)
Available fields
my custom fields doesnt appear.
that i'm doing wrong?
P.D. In actions set settings i have:
Data type: Node
Usage: parameter
Data type: commerce product
Usage: parameter
Comment #3
rszrama commentedYour custom fields don't appear because of the reasons stated at the FAQ article you linked in the original post. Also, you should use the Rules export feature for your rule instead of copying / pasting from the interface... the format is easier to read in here.
Comment #4
dgastudio commentedoh, sorry.
my action set :
but in action set, i can't add a condition as specified in FAQ article.
so, that can i do?
Comment #5
frixos12 commentedsubscribing
Comment #6
rszrama commentedAhh, good call. Yeah, I should've picked up on that... duh. >_<
What you need to do is create a Rules component that will act as a little subroutine in Rules. You'd want it to be a full "rule" component, not just conditions or actions. When you set it up, give it a title like "Update the product display node" and make it accept one node parameter. Then you'll be able to add the condition to check for the fields and the action to update them as necessary.
Once you have the component made, it will be available to call as an action from the Rule you've just exported above. Pass in the display node you've loaded, and voila! It should all work. ; )
Comment #7
frixos12 commentedI was following this issue and i would like to ask some questions.
Lets say i have a term reference field (product categories) in both product display node and commerce product entity.
After updating or saving a commerce product, i want to update product-display : term-refrence field with commerce-product:term-reference field.
As you said, create "rule" component, not just conditions or actions. When you set it up, give it a title like "Update the product display node" and make it accept one node parameter. Then you'll be able to add the condition to check for the fields and the action to update them as necessary.
These conditions and actions should be made inside the component or in the rule that calls this component?
Also if you have unlimited values for your taxonomy term field (checkboxes) how can you pass all the values to the product display :term-reference field??
Thank you
Comment #8
pit_zavra commentedHi kervi i am wondering if you made that rule could you share it please? I tried to make it from your conversation with rszrama , but because i am a newbie i couldn't follow, there was a lot of pieces of code that worked an other that didn't work and i got confused.
Comment #9
dgastudio commentedyes, of course.
finally i opted to use php instead of strange conditions and options.
so, i have used php to set field value from fetched entity.
basically, this code is doing the next thing.
is fetching related product entity, after that, clears the value of product display field and copying the value of product field to product display field.
all this happens on save product display, so i used Admin VBO module with "Save content" option added.
sorry for my english.
Comment #10
pit_zavra commentedThank you very much hope it works on my side :-)
Comment #11
dgastudio commentedu are welcome.
Comment #12
pit_zavra commentedSorry do you have enabled any other module for php?
While i try to input this rule i get a "Missing the required module php" error.
Comment #13
pit_zavra commentedAlso i searched for admin vbo module and the only one i found was admin vbo views.
I think that php error was fixed by enabling php filter.
Comment #14
dgastudio commentedWhile i try to input this rule i get a "Missing the required module php" error.
yes, u have to enable php filter.
Also i searched for admin vbo module and the only one i found was admin vbo views.
yes, u have to install this one and View Bulk Operations module.
Comment #15
pit_zavra commentedThank you