Question

I'm trying to compose the body of an email using PHP evaluation within a rule. The rule is triggered when a new content is saved. Part of the email body is composed using HEREDOC and that works fine. This is the code I'm having trouble with:

//  Provide download link.
 if ($node->field_software_product_sku === "Some Product Name")
     echo "<a href=\"http://www.mywebsite.com/Some Product Name/some.exe\">Trial Version Download Link</a><br />";

The above code comes directly after the ending of the HEREDOC, but, before the closing '?>'. I anticipate that in the future, I will need to add more clauses to the 'if' statement, so, it's important that I get this to work.

I've tried several different incantations for coding the 'if'. I've tried using the token name enclosed in single quotes. And, I've tried using “==” instead of “===”. The only thing that seems to work consistently is commenting out the 'if'. Then, the “Trial Download Link” text does appear in the email. Unfortunately, the rule is to be used for multiple “skus”, so, I need to use the 'if'.

I'm hoping I've made a subtle mistake, or, overlooked something.

Can someone point me in the right direction?

Is there a way to debug the code to see why the 'if' may be failing?

Was it helpful?

Solution

If field_software_product_sku is text field you should test on value of the field something like:

if ($node->field_software_product_sku[LANGUAGE_NONE][0]['value'] === "Some Product Name"){
    echo "<a href=\"http://www.mywebsite.com/Some Product Name/some.exe\">Trial Version Download Link</a><br />";
  }

other ways if it doesn't work, i suggest you to use Devel Module and dump the $node->field_software_product_sku using dpm function to see the value of the field:
dpm($node->field_software_product_sku) and then check on the value of the field.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top