0

I previously asked a question about this, but the question itself has kind of changed, and I don't know if anyone's still following it to begin with.

This is the error I'm seeing:

[06-May-2013 10:50:12] PHP User Warning: Invalid EE Conditional Variable: {if "N"original"$1.50" != ""} in C:\gitRepo\qo5phi\system\expressionengine\libraries\Functions.php on line 2843

I found that the error was being thrown by a custom exception built into expression engine that will do partial matches on variable names if it doesn't find the original one.

From libraries/Functions.php:

// There is a partial variable match being done
// because they are doing something like segment_11
// when there is no such variable but there is a segment_1
// echo  $x[$j]."\n<br />\n";
trigger_error('Invalid EE Conditional Variable: '.$matches[0][$i], E_USER_WARNING);

So in certain iterations of the loop, it's not finding deal_original_price, so it's trying to do a partial match and is finding deal, which evaluates to N in these cases. (As is indicated by the error message.)

I don't know why it's even trying to evaluate deal_original_price in these cases, though, because the entire conditional call is inside another conditional that only runs if deal is Y.

{if deal == "Y" AND coupon == "N"}
    <tr data-deal_id="{deal_id}">
        <td class="productPrice" style="vertical-align: top;">${deal_total}<br />
             <!-- this next line is the one throwing the error -->
            {if deal_original_price && deal_original_price != "" && deal_original_price <> deal_total}
                <span class="originalDealPrice">${deal_original_price}</span><br /><span id="modal_change">Why is there a price difference?</span>
            {if:else}
                <span id="modal_same">Pricing Terms & Conditions</span>
            {/if}
        </td>
    </tr>
{/if}

Any ideas?

3
  • I'm not really sure this should be a new question as it's still related to your original. Commented May 8, 2013 at 21:44
  • @PeterLewis - that may be the case, but the fact is that updated questions don't get bumped to the top of the questions view, which means that very few people would have seen the changes I made to it.
    – EmmyS
    Commented May 8, 2013 at 21:53
  • It's always best to keep it to one question so people can see the full conversation history and what has previously been tried. It also makes it easier for others looking for the same answer to find it quickly with it being accepted and voted up.
    – Ian Young
    Commented May 9, 2013 at 16:48

2 Answers 2

0

I don't know why it's even trying to evaluate deal_original_price in these cases, though, because the entire conditional call is inside another conditional that only runs if deal is Y.

Because EE will parse the template first before acting upon any conditionals, so it will parse the inner conditional variables, even if they are never implemented due to the outer conditionals.

Although I'm surprised you're getting the error you are, I expect it's the way you're using complex conditionals without correctly referencing the variables, therefore EE is having trouble.

Try doing the following:

{if "{deal}" == "Y" AND "{coupon}" == "N"}
    <tr data-deal_id="{deal_id}">
        <td class="productPrice" style="vertical-align: top;">${deal_total}<br />
             <!-- this next line is the one throwing the error -->
            {if "{deal_original_price}" && "{deal_original_price}" != "" && "{deal_original_price}" != "{deal_total}"}
                <span class="originalDealPrice">${deal_original_price}</span><br /><span id="modal_change">Why is there a price difference?</span>
            {if:else}
                <span id="modal_same">Pricing Terms & Conditions</span>
            {/if}
        </td>
    </tr>
{/if}

What I've done is correctly frame your variables using "{blah}" inside the conditional. What can often happen is that a variable is null or empty, so it's important to frame in quotes, but then you need to identify as an EE variable, hence the curly brackets. Consider this:

{if  &&  != "" &&  != 1.50}

Which could be how EE is seeing your conditional if deal_original_price is empty and not correctly framed. Hence you get nasty PHP errors in Functions.php class.

As far as I'm aware <> is not a valid conditional in EE - I haven't checked though! I've changed in the example above.

if "{deal_original_price}" && "{deal_original_price}" != ""

These do the same thing and so only one is needed.

2
  • I'll give that a shot and see if it works. The outer conditional has been in place for a long time - I did not write it, and it has never thrown any errors. It's only the inner one that was just added that's causing the problem.
    – EmmyS
    Commented May 8, 2013 at 21:55
  • Peter, I tried your suggestion and ended up with the same huge error log that I got when I tried it based on a comment in my original ticket. PHP Parse error: syntax error, unexpected T_STRING in C:\gitRepo\qo5phi\system\expressionengine\libraries\Functions.php(680) : eval()'d code on line 214 with a ton of stack trace info.
    – EmmyS
    Commented May 9, 2013 at 14:56
0

What finally worked for me was this:

Instead of using a long conditional containing variables that have similar names to others, I did my conditional processing in my controller and passed back a variable that already knows the answer.

From this:

{if deal_original_price && deal_original_price != "" && deal_original_price <> deal_total}

To this:

  {if costChange == 1}

I also renamed all of my variables to be completely original - i.e. not share ANY part of the variable name with any other variable. I'm sure it's a hack that will have EE gurus yelling, but sometimes you just need to do what works.

3
  • Sometimes you do just need to do what works. :) Keeping it simple is usually the best answer. Glad you got it working. Don't forget to accept this answer if it solves your question.
    – Ian Young
    Commented May 9, 2013 at 16:52
  • Thanks! I'm used to getting flamed for saying things like that... It won't let me accept my own answer until tomorrow.
    – EmmyS
    Commented May 9, 2013 at 17:14
  • The only thing that matters is what makes sense to you and will do when you open up those files again a year down the line. Anything else is fair game. :) There's a delay before you accepting your own answer but if you can remember to hop back then it just helps to keep the site in good health and provide quick answers for people with the same problem. Thanks Emmy.
    – Ian Young
    Commented May 9, 2013 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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