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

sketman’s picture

I 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...

sketman’s picture

OK, 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.

larowlan’s picture

Status: Active » Fixed

You 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.

sketman’s picture

It 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!

larowlan’s picture

Hey thanks, pretty sure the 'entity has field' condition is not a bug in rules but rather a feature for performance etc

sketman’s picture

In 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.

Note on Data Availability: Entity fields will only be available if you have used a condition to verify that the field is present or they are automatically exposed for that particular rule. By default their basic entity type properties should be exposed, but if you need access to a particular field then you can use the "entity has field" condition. If you need to access more then one of the entity's fields then you should use a "data comparison" condition against the entity's type property. Most of the time this is simply some-entity:type in the data select widget.

More information:

sketman’s picture

Sorry, forgot the link:)
More information: Data selection

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Iztok’s picture

Opening 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.

MahmoodZidan’s picture

Issue summary: View changes

I second Iztok's reply.
I don't find that option too.

MahmoodZidan’s picture

Status: Closed (fixed) » Closed (outdated)