Skip to content

Instantly share code, notes, and snippets.

@emjayess
Created December 20, 2012 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emjayess/4345798 to your computer and use it in GitHub Desktop.
Save emjayess/4345798 to your computer and use it in GitHub Desktop.
A drupal 7 workflow rule for drupal commerce that auto-generates 1 new "product display" node (of type "my_product_display") for each newly created product entity; the 'data_set' action establishes a reference from the auto-generated display to the created product.
{ "rules_auto_create_product_display" : {
"LABEL" : "Auto-create product display",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "entity" ],
"ON" : [ "commerce_product_insert" ],
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_sku" } }
],
"DO" : [
{ "entity_create" : {
"USING" : {
"type" : "node",
"param_type" : "my_product_display",
"param_title" : "[commerce-product:title]",
"param_author" : [ "commerce-product:creator" ]
},
"PROVIDE" : { "entity_created" : { "my_new_product_display" : "My New Auto-Created Product Display" } }
}
},
{ "data_set" : {
"data" : [ "my-new-product-display:field-products:0" ],
"value" : [ "commerce-product" ]
}
},
{ "entity_save" : { "data" : [ "my-new-product-display" ] } }
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment