Not sure if this is the correct place for this question, but here goes (crosspost from here):

I am using the Commerce module and have product entities and I'm using nodes in order to separate the product display from the product data.

Originally I was using Product Reference to refer the node to the product, however I require bi-directional references in order to use rules to update/delete product display nodes when changes to the product data occur.

I've added a node_reference field provided by the References module to my product type, however Rules does not appear to recognize the existence of the node_reference field, some I'm unable to fetch the node entity.

Just to run through the workflow in case I'm doing it wrong:

1. Create new Rule with Event: **After updating an existing commerce product**
2. Add Condition: **Entity exists by property**
3. Entity Type to fetch: **Node**
4. Now I think I should be able to select something like **[commerce-product:field-node-reference]** for the property by which the entity is to be selected, however this field does not appear.

Any ideas?

Comments

rszrama’s picture

Status: Active » Closed (works as designed)

This is a pretty common Rules support request. You need to add a condition to check that the field is there before it can be access by other conditions and actions. Find more information here: http://www.drupalcommerce.org/faq/rules-field-data-selection

carn1x’s picture

Thanks a lot :D

Marc Angles’s picture

Edit: My bad. Those fields are provided by commerce_search_api. Very usefull to keep it enabled ;) . So, in case somebody search how to put those product display into scope of rules, commerce_search_api has a usefull function that does that.

One day, in the Data Selector of rules, I had access to a filed named "commerce-product:field-file-for-sale-node:0:nid" which let me fetch the NID...

"field-file-for-sale-node" which is the "back reference" to the node referencing the product was probably given by a function somewhere in the entityreference module or somewhere else... I'm loosing my hairs on this and will probably have to play with components etc. But the mystery persists, how did I had this in the data selector one day and not the day after ?

The error showing up in the summary is : Error: Data selector commerce-product:field-file-for-sale-node:0:nid for parameter id is invalid.

I'll give an update with the exported rules that where functionning before giving me the error.

Here is one of them

{ "rules_when_stock_to_zero" : {
    "LABEL" : "Exclusive stock - Save product display when stock to zero on a product (trigger variations sync rule)",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "pl_stock" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : { "commerce_product_update" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-product:commerce-stock" ], "value" : "0" } },
      { "data_is" : { "data" : [ "commerce-product:commerce-stock-override" ], "value" : 0 } },
      { "entity_is_of_type" : { "entity" : [ "commerce-product" ], "type" : "commerce_product" } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "node",
            "id" : [ "commerce-product:field-file-for-sale-node:0:nid" ]
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "entity_save" : { "data" : [ "entity-fetched" ] } }
    ]
  }
}