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

  1. 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.
  2. The php code use the commerce_display_path backlink exploded url to find the displayed node, then return it.
  3. 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 :


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

  • 1
    Interesting. What 'other rules' are you trying to debug the node in? You see, just because the node is available in one rule doesn't mean it'll be loaded and ready to run in a different one. What a rule has access to depends on the event that triggered the rule... Jan 8 '14 at 18:26
  • In the same "node set" i've inserted, just after the call of 'php custom code', a 'debug value' call on the node-fetched retuned. In 2012, I noticied that you have experienced that (see above linked post comments) and you seem to get it work. could you remember ?
    – Yorguey
    Jan 8 '14 at 19:00
  • I've tried a simple php doing that : get node_id from param and return node loaded : $node=load($node_id); //given in parameter return array("fetched_node"=>$node); Then try to debug the fethed-node value, this does the same, node not filled ! Am I missing something ?
    – Yorguey
    Jan 8 '14 at 20:15
  • You know, it's hard for me to figure it out without seeing the entirety of your rule. Is the actual $node_id actually filled itself? Jan 8 '14 at 20:44
  • node_id is an 'in' parameter of type integer. As it is a component rule, i could execute the rule from rules component interface. The node_id is asked in form then the rule is launched, the paramters goes in (the dpm() inside the php displays the correct value), the node is loaded (another dpm() shows it to me) i think that the return causes the problem not matching what it is supposed to do. i've tried returing $node, array(), nid only .... nothing works. i've you experienced building "provided variable" in components which works ?
    – Yorguey
    Jan 8 '14 at 21:30

In fact returning variables (providers) from a custom php code doesn't work ! If you do it in a module the same code works ! Rules bug ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.