emjayess
12/20/2012 - 3:06 PM

A drupal 7 workflow rule for drupal commerce that auto-generates 1 new "product display" node (of type "my_product_display") for each newly

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" ] } }
    ]
  }
}