I ve found something quite interesting in an other post Discount based on a field in product display node in Drupal Commerce?
It describe a way to get the ‘node display’ associated with a line_item
- Build a component rules action set with custom php code in it, providing a ‘node_fecthed’ provider variable and then use it with other rules to do what you need.
- The php code use the commerce_display_path backlink exploded url to find the displayed node, then return it.
-
The given code is the following :
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item); $url = $line_item_wrapper->commerce_display_path->value(); $url_parts = explode('/', $url); $nid = $url_parts[1]; return array('node_fetched'=> $node);
Just before the return line, i added, regarding to a comment suggestion from the original post, 2 lines :
$node=node_load($nid); dpm($node);
when rules is run, devel dpm() displays the right associated node as expected. But when in an other rules i try to display/debug/use the ‘node_fetched’ it appears to do nothing as if it was set to null. What may be wrong with that ? Any suggestions will be appreciated as i’m going mad with that for 2 days. Thx