Automatic product display creation while creating product type in drupal commerce

This post is just a repost of drupal.org information. The link to this post was lost unfortunately but information is very helpfull, so let's begin. In drupal commerce creating product display is separated from creating product type. it means that one product type can have multiple product displays. But in most cases we don't need such functionality, then we should implement one rule using the module with the same name - Rules.

You can find rules user interface using path: root/admin/config/workflow/rules. If you find nothing you should check are the Rules module and Rules UI module turned on. If not turn them on. Then you should find the link "Import rule" and follow it. then you should change some constants inside code given below. Then just paste it in textarea and press Import button below.

* PRODUCT_TYPE (product type that has been created)

* NODE_TYPE (node type being created)

* PRODUCT_REFERENCE (field that will reference the created product)

* PRODUCT_TYPE (product type that has been created)

* NODE_TYPE (node type being created)

* PRODUCT_REFERENCE (field that will reference the created product)  replace underscores with hyphens

{ "Cr\u00e9 Automatic product display creation" :
{ "LABEL" : "Cr\u00e9 Automatic product display creation",
"PLUGIN" : "reaction rule", "REQUIRES" : [ "rules", "entity" ],
"ON" : [ "commerce_product_insert" ],
"DO" : [
{ "entity_create" : {
"USING" : {
"type" : "node",
"param_type" : "NODE_TYPE",
"param_title" : [ "commerce-product:title" ],
"param_author" : [ "commerce-product:creator" ]
},
"PROVIDE" :
{ "entity_created" :
{ "entity_created" : "PRODUCT_TYPE" }
}
}
},
{ "list_add" :
{"list" : [ "entity-created:PRODUCT_REFERENCE" ],
"item" : [ "commerce-product" ]
}
}
]
}
}

That's all, Good luck!!! Continue doing Drupal.

Rating: 
10 out of 10 based on 3 ratings.
Tags: