Hi

I'm looking for a de-facto set of rules for creating product display nodes when new product entities are created. I'd also like rules that delete and update product display nodes when their associated product entities are deleted / updated.

I'm going to collate those rules I've found in various issue queues and threads. I'd appreciate if anyone could post their rules here too.

Ultimately I think it would be good to have a module which can be used to add the necessary rules automatically.

CommentFileSizeAuthor
#12 update-rule-log.png58.7 KBkeithm
#12 delete-rule-log.png55.92 KBkeithm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lukus’s picture

Creation

From http://drupal.org/node/971484#comment-4188422

{ "rules_new_commerce_product_display" : {
    "LABEL" : "Create Product Display for new Commerce Product",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_product" ],
    "ON" : [ "commerce_product_insert" ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "product_display",
            "param_title" : "[product:title]",
            "param_author" : [ "product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "product_display_created" : "Created product display" } }
        }
      },
      { "data_set" : {
          "data" : [ "product-display-created:field-product-reference" ],
          "value" : [ "product" ]
        }
      }
    ]
  }
}

From http://drupal.org/node/971484#comment-4188422

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

From http://drupal.org/node/971484#comment-4729100

{ "rules_create_product_node" : {
    "LABEL" : "Create Product Node",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "proddisp" : "proddisp" } } } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "commerce_product",
            "param_sku" : "[node:nid]",
            "param_type" : "basic_product",
            "param_title" : "node:title] ([node:nid])",
            "param_creator" : [ "node:author" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : { "data" : [ "entity-created:commerce-price:amount" ], "value" : "10000" } },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } },
      { "data_set" : { "data" : [ "node:field-prodref" ], "value" : [ "entity-created" ] } }
    ]
  }
}

From http://drupal.org/node/971484#comment-4812190

{ "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" ]
        }
      }
    ]
  }
}
lukus’s picture

Create / Update / Delete

From http://drupal.org/node/971484#comment-4753706

{ "rules_create_product" : {
    "LABEL" : "Create Product",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "data_is_empty" : { "data" : [ "node:source" ] } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "commerce_product",
            "param_sku" : "[node:field-prodcode]",
            "param_type" : "product",
            "param_title" : "[node:title]",
            "param_creator" : [ "node:author" ],
            "param_commerce_price" : [ "node:field-price" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-images" ],
          "value" : [ "node:field-images" ]
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } },
      { "data_set" : { "data" : [ "node:field-product" ], "value" : [ "entity-created" ] } }
    ]
  }
}
{ "rules_update_product" : {
    "LABEL" : "Update Product",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "REQUIRES" : [ "rules", "php" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "NOT data_is_empty" : { "data" : [ "node:field-product" ] } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "commerce_product",
            "id" : [ "node:field-product:product-id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "data_set" : { "data" : [ "entity-fetched:sku" ], "value" : "[node:field-prodcode]" } },
      { "data_set" : { "data" : [ "entity-fetched:creator" ], "value" : [ "node:author" ] } },
      { "data_set" : { "data" : [ "entity-fetched:title" ], "value" : "[node:title]" } },
      { "data_set" : {
          "data" : [ "entity-fetched:commerce-price" ],
          "value" : [ "node:field-price" ]
        }
      },
      { "php_eval" : { "code" : "$entity_fetched-\u003efield_images = $node-\u003efield_images;\r\n$entity_fetched-\u003efield_notes = $node-\u003efield_notes;\r\n" } },
      { "entity_save" : { "data" : [ "entity-fetched" ], "immediate" : 1 } }
    ]
  }
}
{ "rules_delete_product" : {
    "LABEL" : "Delete Product",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_delete" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "NOT data_is_empty" : { "data" : [ "node:field-product" ] } }
    ],
    "DO" : [ { "entity_delete" : { "data" : [ "node:field-product" ] } } ]
  }
}
rszrama’s picture

If this replaces that other issue, can you close it out and point people here? We can always make this an FAQ answer or documentation section on DrupalCommerce.org, too, and close both out. : )

rfay’s picture

@lukus I think it would be more useful if you'd create a feature module with these rules and put it in a sandbox. it's really only accessible to the most die-hard and is unmaintainable here.

-Randy

lukus’s picture

@rfay - Good idea.

I'd be happy to make a module .. but first I'd like an overview of which rules have been used successfully and which are the most useful. I'm thinking of this as stage 1 in the process.

Also, I'm imagining that any module will need to map a variety of user-specific field names to the required rule definitions; so the task of modularising this might be less trivial than it first appears? ... or am I over thinking the task?

rfay’s picture

@lukus if you make a ruleset as simple as you can, and publish it as a feature, then it can at least serve as a model. And the issue queue for that feature module can be used to discuss and improve it.

rupertj’s picture

Following Randy's suggestion, here's a feature that contains a Product content type, and the rules necessary to create a new node of that type and keep it updated with the right title and owner:

https://drupal.org/sandbox/rupertj/1306212

It doesn't actually use the rules in this issue (although they were really helpful for getting my head round this, so thanks lukus!). The create rule is very similar to one above, but the update and delete rules are quite different, as the above rules react to updates to the node and update the product. The ones in the sandbox project react to changes to the product and keep the display up to date. (I thought it made more sense to work this way, as follows the creation rule.)

Known issues:
The update rule doesn't work without a change to commerce_product_reference. Please see this issue: https://drupal.org/node/1306106 (I believe it's a bug either in commerce_product_reference or the entity system in general.)

The delete rule suffers from the same bug, but even with that change it can't find the display node. More eyes on the problem would be greatly appreciated :)

Anonymous’s picture

I tried out the feature set from #7 but I can't get it to work even with the changes to commerce_product_reference. Creation of nodes works, but update/delete is stuck because trying to reference the node within rules gives an error:

Warning: array_values() expects parameter 1 to be array, null given in rules_action_entity_query() (Zeile 56 von /home/mediagen/public_html/freestylecooking/sites/all/modules/rules/modules/entity.eval.inc).

Unfortunately I don't know wether this is a problem of rules, entities or commerce. I tried both dev versions and "stable" releases of those modules, doesn't change anything either.

DigitalFrontiersMedia’s picture

Title: Rules to mirror product displays when products created/updated/deleted » A de-facto set of rules for creating product displays which mirror products (when added / altered / removed).

I've used the Rules from #2. Create and Update work fine in my setup after a few modifications. But Delete doesn't work at all. Is this because the event is "After deleting content" instead of a non-existent "Before deleting content"? After all, if it's using the product reference in the Product Display to figure out which Product to delete and the Product Display has been deleted, how can it get the now deleted product reference value?

Is there any way to create a custom event here for "before deleting content"? Am I correct in stating that NodeAPI doesn't have any hooks/switches that occur just prior to deletion? Validation hooks are called before processing a deletion request. This can be demonstrated by creating a node with fields X & Y and leaving Y empty, changing Y to Required, then going back to the node with the empty Y value and trying to delete the node. It won't allow you to delete the node until you actually supply a mandatory value for Y. Any way to use this validation process to our advantage for this?

Reason why I'd prefer deleting Product Display over Product is we're using Drupal Commerce to organize a catalog of items IN ANTICIPATION of providing ecommerce solutions for them later. That way it's not much more effort to build it now but will save us a complete overhaul rebuild later if/when they say "hey, we no longer just want to list nodes, can we set it up so that we can actually sell these online?" Thus, in our case, it's easier to provide options to the end user/client to create/update/delete these Product Display nodes than to confuse them with Store Administration options to gain access to the Product management UI when technically they don't have (nor have they yet requested) an ecommerce store.

paulmarc’s picture

@DigitalFrontiersMedia, how were you able to make a rule for updating the displays?
The "Create" was simple enough:
Event: "After saving a new commerce product"
No conditions
Actions:
1. "Create a new entity (type = node, ...)"
2. "Set a data value (entity-created:field-product-reference = commerce-product)"

However, no matter what I do with Rules to "Fetch entity by property", I get the "null given in rules" error... The entity is just not being fetched!
I tried the "After updating an existing commerce product" and "before saving commerce product"... To no avail...
Thank you for clearing this up!

bojanz’s picture

keithm’s picture

FileSize
55.92 KB
58.7 KB

Confirming what rupertj said in #7. After applying the commerce_product_reference patch from #1356006: Fix entity property info of product / customer profile / line item reference fields the create and update rules work as designed, but the delete rule fails. The node fetch action is identical in the update and delete rules.

The rules log for the update rule:

update rule log

The delete rule does not work:

delete rule log

In #9, @DigitalFrontiersMedia conjectured that we need a new 'Before deleting content' event. Since these events are provided by EntityDefaultRulesController::eventInfo() that would have to be coordinated with the entity maintainer.

On the other hand, commerce_product_reference_commerce_product_delete() removes the referenced product before the rule gets a chance to run, so of course no product reference is found by the rule.

Comments or suggestions?

rszrama’s picture

Title: A de-facto set of rules for creating product displays which mirror products (when added / altered / removed). » Rules to mirror product displays when products created/updated/deleted

Sorry, without showing an export of your Delete Rule, there's nothing we can really do to help. I don't see a Rule with that name anywhere above, so I'm assuming it's something custom. Are you properly looping over the return value of your entity fetch? Notice it's returning a list, not a single entity.

keithm’s picture

@rszrama: Thanks for your comment. My rule titles are a little different but I believe the logic is identical to rupertj's sandbox project https://drupal.org/sandbox/rupertj/1306212.

Here are my rules. The create and update rules work; the delete fails as described in #12.

{ "rules_create_event_display" : {
    "LABEL" : "Create Event Display",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "event_display",
            "param_title" : [ "commerce-product:title" ],
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-product" ],
          "value" : [ "commerce-product" ]
        }
      }
    ]
  }
}
{ "rules_update_event_display" : {
    "LABEL" : "Update Event Display",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_update" ],
    "DO" : [
      { "entity_query" : {
          "USING" : {
            "type" : "node",
            "property" : "field_product",
            "value" : [ "commerce-product:product-id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-fetched:0:title" ],
          "value" : [ "commerce-product:title" ]
        }
      },
      { "data_set" : {
          "data" : [ "entity-fetched:0:author" ],
          "value" : [ "commerce-product:creator" ]
        }
      },
      { "entity_save" : { "data" : [ "entity-fetched:0" ] } }
    ]
  }
}
{ "rules_delete_event_display" : {
    "LABEL" : "Delete Event Display",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_delete" ],
    "DO" : [
      { "entity_query" : {
          "USING" : {
            "type" : "node",
            "property" : "field_product",
            "value" : [ "commerce-product:product-id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "entity_delete" : { "data" : [ "entity-fetched:0" ] } }
    ]
  }
}
DigitalFrontiersMedia’s picture

Title: A de-facto set of rules for creating product displays which mirror products (when added / altered / removed). » Rules to mirror product displays when products created/updated/deleted

@paulmarc Well, I think my rules are a little different/backwards from yours. I'm having the user create and update product DISPLAYS which are triggering the creation and updating of the actual product entities in Drupal Commerce. This is due to some UI/UX and business logic concerns with our client.

FTR, below are the rules I'm using. Change machine & field names to taste....

To create a Product Entity by creating a Product Display Node:

{ "rules_create_product" : {
    "LABEL" : "Create Product",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "data_is_empty" : { "data" : [ "node:field-productref" ] } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "commerce_product",
            "param_sku" : "[node:field-prodcode]",
            "param_type" : "product",
            "param_title" : "[node:title]",
            "param_creator" : [ "node:author" ],
            "param_commerce_price" : [ "node:field-price" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } },
      { "data_set" : { "data" : [ "node:field-productref" ], "value" : [ "entity-created" ] } }
    ]
  }
}

To update a Product Entity by updating a Product Display Node:

{ "rules_update_product" : {
    "LABEL" : "Update Product",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "NOT data_is_empty" : { "data" : [ "node:field-productref" ] } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "commerce_product",
            "id" : [ "node:field-productref:product-id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "data_set" : { "data" : [ "entity-fetched:sku" ], "value" : "[node:field-prodcode]" } },
      { "data_set" : { "data" : [ "entity-fetched:creator" ], "value" : [ "node:author" ] } },
      { "data_set" : { "data" : [ "entity-fetched:title" ], "value" : "[node:title]" } },
      { "data_set" : {
          "data" : [ "entity-fetched:commerce-price" ],
          "value" : [ "node:field-price" ]
        }
      },
      { "entity_save" : { "data" : [ "entity-fetched" ], "immediate" : 1 } }
    ]
  }
}

To delete a Product Entity by deleting a Product Display Node (DOESN'T WORK):

{ "rules_delete_product" : {
    "LABEL" : "Delete Product",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_delete" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "NOT data_is_empty" : { "data" : [ "node:field-productref" ] } }
    ],
    "DO" : [ { "entity_delete" : { "data" : [ "node:field-productref" ] } } ]
  }
}
droplet’s picture

Thanks for the sharing. It's good but bring other UX issues. Eg. no way to add 2 product to one display anymore.

anyone interested to create http://drupal.org/project/references_dialog like modules for DC.

DigitalFrontiersMedia’s picture

droplet - true. My use-case involved only a 1-to-1 display/entity relationship. I see what you're getting at with references_dialog. Good idea--a contrib to support this would be better than a set of arbitary rules.

podarok’s picture

#17 agree!

decibel.places’s picture

I tried to dynamically set the node type from the product type (both named "video") using
"param_type" : [ "commerce-product:type" ],

{ "rules_after_saving_a_new_commerce_product" : {
    "LABEL" : "After saving a new commerce product",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "commerce", "product" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "commerce_product" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : [ "commerce-product:type" ],
            "param_title" : "[commerce-product:title]",
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created_product_node" : "Product Node" } }
        }
      }
    ]
  }
}

it created the correct type of node, but I could not add the product reference:

      { "data_set" : {
          "data" : [ "entity-created:field-product-reference" ],
          "value" : [ "commerce-product" ]
        }

I kept getting an error, I tried both methods in #1

Integrity check for the imported configuratoin [sic] failed. Error message: Data selector entity-created:field-product-reference for parameter data is invalid..

so I had to explicitly set the node type, with a condition to detect the product type by the filefield name on the video product using
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_vid_commerce_file" } }
],

{ "rules_create_product_display_when_product_created" : {
    "LABEL" : "Create Product Display when Product Created",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "commerce", "product" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_vid_commerce_file" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
           "param_type" : "video",
            "param_title" : "[commerce-product:title]",
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Entity Created" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-product-reference" ],
          "value" : [ "commerce-product" ]
        }
      }
    ]
  }
}

But now I'm thinking I might be able to use a generic product node type for various media without detecting the product type, and filter them later in Views...

pcambra’s picture

I think it's safer to use list add instead of dataset, example of rule creating a product display on product creation:

{ "rules_create_event_display" : {
    "LABEL" : "Create Event Display",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "product_display",
            "param_title" : [ "commerce-product:title" ],
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "list_add" : {
          "list" : [ "entity-created:field-product" ],
          "item" : [ "commerce-product" ]
        }
      }
    ]
  }
}
polmaresma’s picture

#20 Works fine!

I understand the reasons for different products and displays, but in simple scenarios I'd prefer the ability to use/theme products as entities directly.

Thank's for all.

decibel.places’s picture

working backwards now, creating a product when a display is created - the exports above are not working for me, they fail on data types

this has been working (with some messages useful for debugging)

also I have been using commerce_autosku for the product to override what is set here, to ensure a unique SKU with the product id; I had trouble passing the [node:nid] as a unique value, and could not get a token for a raw timestamp

{ "rules_create_product" : {
    "LABEL" : "Create Product",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "product_display" : "product_display" } }
        }
      },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_product_reference" } },
      { "AND" : [ { "data_is_empty" : { "data" : [ "node:field-product-reference" ] } } ] }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Conditions passed" } },
      { "entity_create" : {
          "USING" : {
            "type" : "commerce_product",
            "param_sku" : "[node:field-media-type:name]-[node:author:uid]",
            "param_type" : "news_item",
            "param_title" : "[node:title]",
            "param_creator" : [ "node:author" ],
            "param_commerce_price" : [ "node:field-display-price" ]
          },
          "PROVIDE" : { "entity_created" : { "product_created" : "Created product" } }
        }
      },
      { "entity_save" : { "data" : [ "product-created" ], "immediate" : 1 } },
      { "drupal_message" : { "message" : "Entity Id is [product-created:product-id]" } },
      { "data_set" : {
          "data" : [ "node:field-product-reference" ],
          "value" : [ "product-created" ]
        }
      }
    ]
  }
}

the key difference is adding the product reference field as a condition, which makes its data available later:


{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_product_reference" } },
{ "AND" : [ { "data_is_empty" : { "data" : [ "node:field-product-reference" ] } } ] }

also re #20, the list did not work for me, I think it requires a loop?

chefnelone’s picture

I'm looking for a rule to just make the oposite to this rule does. I mean: when I delete a product display the the product should be deleted as well.

agileadam’s picture

I used #20 as a guide while I stepped through the setup of this rule through the rules UI. Worked like a charm. Thanks!

Bricks and Clicks Marketing’s picture

I'm trying to import #20 as a rule and get this error:

Integrity check for the imported configuratoin failed. Error message: The data type of the configured argument does not match the parameter's list requirement..

Is there something I'm missing?

decibel.places’s picture

re #25

I said earlier

re #20, the list did not work for me, I think it requires a loop?

see docs http://drupal.org/node/1300058
and video tutorial http://dev.nodeone.se/node/988

Bricks and Clicks Marketing’s picture

Thanks for the clue - I'm unfortunately finding this to be rather confusing still. When I go to create a Rules Component, 'List of Commerce Product Items' does not seem to work. When I try to create a loop after that, none of the data selectors match 'entity-created:field-product'.

vlkff’s picture

This module does the backwards - sync products to nodes (with no rules integration), so might be helpful
http://drupal.org/sandbox/vlkff/1516510

Bricks and Clicks Marketing’s picture

Thanks - your link led me to a Rule with an explanation :)

http://drupal.org/node/971484#comment-4812190

decibel.places’s picture

re #29

In fact that code was here already in the first comment: http://drupal.org/comment/reply/1300170/5837758#comment-5077400
---

re #31

@arphaus if that info is missing here and important, can you repost the explanation here?

Bricks and Clicks Marketing’s picture

The explanation made the difference.

OMGABRIEL’s picture

Hi all, I want to know if I can help with this: Add a field Category to type Product , to catalog products. I can generate a Rule to automatically take me in Category: Product display. I managed to insert a Rule that automatically agrege me the product, but does not take the field value that I add Category: Product Type
admin/commerce/products/types/product/fields
regards
Gabriel

woprrr’s picture

I created a rule that allows me to create content with the submision of a product, but with several types of products, each corresponding with a content type example: Product manga -> content manga.

Now here is my rule.

{ "Cr\u00e9ation automatique des affichages front" : {
    "LABEL" : "Cr\u00e9ation automatique des affichages front",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_insert" ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "produits_mangas",
            "param_title" : [ "commerce-product:title" ],
            "param_author" : [ "commerce-product:creator" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "list_add" : {
          "list" : [ "entity-created:field-product" ],
          "item" : [ "commerce-product" ]
        }
      }
    ]
  }
}

What I would do is create the conditions so that I can check on what product type I create the entity and therefore it creates the right kind of content.

So, in my case I want to create:

Product type: Manga sends Content type: Manga

Product type: Content type sends Comics: Comics

xandeadx’s picture

Is it possible to delete product display after delete product? #2 not work

cedricvg’s picture

Does anyone have a solution based on rules on how to do this with the multilanguage modules?

-I installed Entity Translation, Entity Translation Upgrade, Multilingual - Internationalization, Title modules.

I want to be able to translate my products and it should update, the display node (translation) in the curent language...

For example
-If I create a translation of my product I want it to create a translation of the display Node with the translated title of my product in my display node title.
-If i update a translation (eg title) of my product I want it to update the display node translation with the modified values.

I don't want to spend time in programming if it can be done with rules

leevh’s picture

Curious if anyone has found a way to delete product display upon product deletion? I just ran into this issue and it seems perfectly described in #9 above.

AlfTheCat’s picture

@leevh I found that the module commerce_backoffice makes the workflow a lot easier. I'm not sure yet how well it works with deleting products after displays are removed, haven't tested that yet but I can sure recommend the module in general. It alleviates the pain of this separation of products and product displays considerably.

bojanz’s picture

Backoffice uses Inline Entity Form to handle products from the node form.

gettysburger’s picture

I am looking for a rule that will trigger when a product is created and attach it via a product reference to display nodes that already exist. Each product is a Show Time for a movie and the display nodes are the actual Movies with generic info such as a link to a trailer and an image. There are always many Show Time products for each Movie display node. They each have a common field called field_film_code.

Is this the correct place to ask for help with this? Thanks.

El Bandito’s picture

Pcambra

I can't get this to work. Getting the same error as #25. However I have managed to manually create a rule that replicates the rule, but using data set rather than list add.

Would be great if you clarify why list add is "safer".

Thanks

El Bandito’s picture

Issue summary: View changes

Update

Lukish’s picture

Issue summary: View changes

Hello,

in conclusion, is there a (maybe official?) set of working rules to do this job? Can you link or copy them here?

bloomt’s picture

I also get the same error as #25 but am very interested in automating this process with rules. Anyone have create/update/delete rules that work?

woprrr’s picture

@bloomt You have seen this rule : https://www.drupal.org/node/1300170#comment-6090368

For me this rule works fine.

Yuri’s picture

I agree that this should be in the Commerce Rules by default. Or, included in the Commerce Rules Extra https://www.drupal.org/project/issues/commerce_rules_extra