Search code examples
drupaldrupal-7content-typedrupal-commercedrupal-rules

Rule-based node creation: commerce product + product display node set


I'm trying to bind a Commerce product type to my own custom type node (serving as a display node). The goal is to enter new data in as few places as possible. I'm therefore exploring a rule-based creation of one type upon creation of the other. Seems like both directions are working. Of the two though, I prefer automatic creation of a Commerce Product upon user creation of Custom Type node, which will then serve as a product display.

I was wondering if anyone has been through this choice and could recommend this. Also, is the commerce_product_display_manager module necessary?


Solution

  • Commerce Product Display Manager is not necessary, I've gotten this to work and I've never used that module.

    I went for the route of automatically creating a Node after saving the Product.

    Below is my Rules export for this:

    { "rules_create_product_display" : {
        "LABEL" : "Create Product Display",
        "PLUGIN" : "reaction rule",
        "REQUIRES" : [ "rules", "entity" ],
        "ON" : [ "commerce_product_insert" ],
        "IF" : [
          { "data_is" : { "data" : [ "commerce-product:type" ], "value" : "**PRODUCT_TYPE**" } }
        ],
        "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" : "Created entity" } }
            }
          },
          { "data_set" : {
              "data" : [ "entity-created:**PRODUCT_REFERENCE**" ],
              "value" : [ "commerce-product" ]
            }
          }
        ]
      }
    }
    

    You'll need to substitute your own values for:

    • PRODUCT_TYPE (product type that has been created)
    • NODE_TYPE (node type being created)
    • PRODUCT_REFERENCE (field that will reference the created product)

    Sorry I can't dedicate more time to a better answer now, let me know if you'd like me to elaborate on the process of creating the above using the GUI