Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#12 | update-rule-log.png | 58.7 KB | keithm |
#12 | delete-rule-log.png | 55.92 KB | keithm |
Comments
Comment #1
lukusCreation
From http://drupal.org/node/971484#comment-4188422
From http://drupal.org/node/971484#comment-4188422
From http://drupal.org/node/971484#comment-4729100
From http://drupal.org/node/971484#comment-4812190
Comment #2
lukusCreate / Update / Delete
From http://drupal.org/node/971484#comment-4753706
Comment #3
rszrama CreditAttribution: rszrama commentedIf 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. : )
Comment #4
rfay@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
Comment #5
lukus@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?
Comment #6
rfay@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.
Comment #7
rupertj CreditAttribution: rupertj commentedFollowing 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 :)
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedI 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.
Comment #9
DigitalFrontiersMediaI'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.
Comment #10
paulmarc CreditAttribution: paulmarc commented@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!
Comment #11
bojanz CreditAttribution: bojanz commentedI'm guessing "entity fetch by property" failing is fixed by #1356006: Fix entity property info of product / customer profile / line item reference fields.
Comment #12
keithm CreditAttribution: keithm commentedConfirming 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:
The delete rule does not work:
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?
Comment #13
rszrama CreditAttribution: rszrama commentedSorry, 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.
Comment #14
keithm CreditAttribution: keithm commented@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.
Comment #15
DigitalFrontiersMedia@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:
To update a Product Entity by updating a Product Display Node:
To delete a Product Entity by deleting a Product Display Node (DOESN'T WORK):
Comment #16
droplet CreditAttribution: droplet commentedThanks 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.
Comment #17
DigitalFrontiersMediadroplet - 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.
Comment #18
podarok#17 agree!
Comment #19
decibel.places CreditAttribution: decibel.places commentedI tried to dynamically set the node type from the product type (both named "video") using
"param_type" : [ "commerce-product:type" ],
it created the correct type of node, but I could not add the product reference:
I kept getting an error, I tried both methods in #1
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" } }
],
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...
Comment #20
pcambraI think it's safer to use list add instead of dataset, example of rule creating a product display on product creation:
Comment #21
polmaresma CreditAttribution: polmaresma commented#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.
Comment #22
decibel.places CreditAttribution: decibel.places commentedworking 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
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?
Comment #23
chefnelone CreditAttribution: chefnelone commentedI'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.
Comment #24
agileadamI used #20 as a guide while I stepped through the setup of this rule through the rules UI. Worked like a charm. Thanks!
Comment #25
Bricks and Clicks MarketingI'm trying to import #20 as a rule and get this error:
Is there something I'm missing?
Comment #26
decibel.places CreditAttribution: decibel.places commentedre #25
I said earlier
see docs http://drupal.org/node/1300058
and video tutorial http://dev.nodeone.se/node/988
Comment #27
Bricks and Clicks MarketingThanks 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'.
Comment #28
vlkff CreditAttribution: vlkff commentedThis module does the backwards - sync products to nodes (with no rules integration), so might be helpful
http://drupal.org/sandbox/vlkff/1516510
Comment #29
Bricks and Clicks MarketingThanks - your link led me to a Rule with an explanation :)
http://drupal.org/node/971484#comment-4812190
Comment #30
decibel.places CreditAttribution: decibel.places commentedre #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?
Comment #31
Bricks and Clicks MarketingThe explanation made the difference.
Comment #32
OMGABRIEL CreditAttribution: OMGABRIEL commentedHi 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
Comment #33
woprrr CreditAttribution: woprrr commentedI 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.
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
Comment #34
xandeadx CreditAttribution: xandeadx commentedIs it possible to delete product display after delete product? #2 not work
Comment #35
cedricvg CreditAttribution: cedricvg commentedDoes 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
Comment #36
leevh CreditAttribution: leevh commentedCurious 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.
Comment #37
AlfTheCat CreditAttribution: AlfTheCat commented@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.
Comment #38
bojanz CreditAttribution: bojanz commentedBackoffice uses Inline Entity Form to handle products from the node form.
Comment #39
gettysburger CreditAttribution: gettysburger commentedI 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.
Comment #40
El Bandito CreditAttribution: El Bandito commentedPcambra
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
Comment #40.0
El Bandito CreditAttribution: El Bandito commentedUpdate
Comment #41
Lukish CreditAttribution: Lukish commentedHello,
in conclusion, is there a (maybe official?) set of working rules to do this job? Can you link or copy them here?
Comment #42
bloomt CreditAttribution: bloomt commentedI 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?
Comment #43
woprrr CreditAttribution: woprrr commented@bloomt You have seen this rule : https://www.drupal.org/node/1300170#comment-6090368
For me this rule works fine.
Comment #44
Yuri CreditAttribution: Yuri commentedI 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