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.
I would like to create a rule triggered by event "After updating an existing commerce order", where I want to fetch bought node from the order and perform some changes on it.
I am currently successfully fetching line items from the order, as well as the "Pay to publish" type products, however I am not able to fetch the bought node itself. I do not see any product or node reference field there and therefore I do not have any "hook" to get it.
Could you please advice me how to do this?
Thanks in advance.
Comments
Comment #1
sketman CreditAttribution: sketman commentedI was thinking, if no better choice, of the following solution:
- create a new entity reference field on the node type that has to be bought
- automatically prepopulate the field by using Entityreference prepopulate , what will create a relationship
- fetch the bought node with rules using this reference field
I will give it a try if it works...
Comment #2
sketman CreditAttribution: sketman commentedOK, so taking back. I found field commerce_node_checkout_node in Commerce Node Checkout line item type. I can get and do all I need through this field.
Comment #3
larowlanYou just might need to add a line item is of type condition to ensure rules gets the field list correctly but otherwise this should work. If not, it's a rules issue.
Comment #4
sketman CreditAttribution: sketman commentedIt works for me perfectly. I can see the bought node when drill down in list of available items, under fetched line item. Then I can bring up all other fields not visible by default (bug in Rules) adding condition "entity has field".
Thank you for your input and for creating this useful module!
Comment #5
larowlanHey thanks, pretty sure the 'entity has field' condition is not a bug in rules but rather a feature for performance etc
Comment #6
sketman CreditAttribution: sketman commentedIn current version of Rules, only default fields of entity are available. So if you add your own fields, they are not available in the selection list. You have to bring them up using condition "Entity has field". I read somewhere (or heard in some screencast) that this is a bug in Rules and it should be (hopefully) solved in some of the future major versions of Rule.
More information:
Comment #7
sketman CreditAttribution: sketman commentedSorry, forgot the link:)
More information: Data selection
Comment #9
Iztok CreditAttribution: Iztok commentedOpening since it looks like something has changed in the Commerce module.
commerce_node_checkout_node is no longer available, and I can not find any way to get the node object from the order.
Comment #10
MahmoodZidan CreditAttribution: MahmoodZidan commentedI second Iztok's reply.
I don't find that option too.
Comment #11
MahmoodZidan CreditAttribution: MahmoodZidan commented