Jump to content

Resolved - Problem with an 'if' on email template


Guest PanKBoy

Recommended Posts

Guest PanKBoy

Hello,

On the mail template, i want to set the value of shipping cost field to 'A Calcular' when shipping cost is 0.00€ and set the value to shipping cost when is different from 0.00€.

This should be something like that:

{if ({$DATA.shipping}) == 0.00 }(A Calcular)

{/if}{$DATA.shipping}

But this isn't working, and i can't even see the error.

Anyone can help me?

Thank you! ;)

Link to comment
Share on other sites

Please try:

{if floatval($DATA.shipping) == 0 }(A Calcular){else}{$DATA.shipping}{/if}

The if/else construct originally posted is not formatted correctly, and by using floatval(), which returns the first occurrence of anything that looks like a float-type number, we can simply not worry about whatever currency symbols may accompany the string.

Link to comment
Share on other sites

Guest PanKBoy

Please try:

{if floatval($DATA.shipping) == 0 }(A Calcular){else}{$DATA.shipping}{/if}

The if/else construct originally posted is not formatted correctly, and by using floatval(), which returns the first occurrence of anything that looks like a float-type number, we can simply not worry about whatever currency symbols may accompany the string.

I tried that way and got an error:

[Exception] /home/solexabc/public_html/loja/includes/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:627 - Syntax Error in template "e0337cf6a65f2924d31c3fd89a8274821a7769f7" on line 64 "<span style="color: rgb(40, 40, 40); font-family: helvetica, arial, sans-serif; font-size: 14px; line-height: 22px; ">{if floatval(</span><span style="color: rgb(40, 40, 40); font-family: helvetica, arial, sans-serif; font-size: 14px; line-height: 22px; ">$DATA.shipping) == 0 }(A Calcular)</span><span style="color: rgb(40, 40, 40); font-family: helvetica, arial, sans-serif; font-size: 14px; line-height: 22px; ">{else}</span><span style="color: rgb(40, 40, 40); font-family: helvetica, arial, sans-serif; font-size: 14px; line-height: 22px; ">{$DATA.shipping}</span><span style="color: rgb(40, 40, 40); font-family: helvetica, arial, sans-serif; font-size: 14px; line-height: 22px; ">{/if}</span></td>" - Unexpected "<", expected one of: "","" , ")"

Can you help me?

Link to comment
Share on other sites

It seems the range of code from <span ...> to </span> is the display formatting of the text from whatever you copied what I suggested you use.

If you copy/paste this:

Hello!

into a rich-text-editor (which CubeCart uses), you will get:

Hello!

But you don't want that! You don't want the HTML styling codes included in the copy/paste operation to be included with the actual stuff you do want -- just plain Hello!

I suggest you go back to editing the mail template, remove wat you added, switch the editor to "source-code" mode (usually the upper-left most icon on the editor's toolbars), then add the code I suggested. Source-code mode allows you to paste anything guaranteed as plain text.

Link to comment
Share on other sites

Guest PanKBoy

Thank you for the explanation! Now there is no errors! :)

But now the function doesn't work! I've tested the code here: http://codepad.org/Wf7faRWt

The problem now is the floatval function, when the string has a € on the first element, the function returns every time 0!

Do you now how to return the value 5 from the string '€5.00'?

Sorry for bother you but i don't know php! :

Thank you! ;)

Link to comment
Share on other sites

Your original request indicated your email has the Euro symbol AFTER the price, not before. It sounds like the fix would work if you moved the position of the symbol. If that would be acceptable you should be able to change that position in the Currencies table of Admin.

Link to comment
Share on other sites

Good Lord, you guys really don't get it... I appreciate you all trying to help but all you're doing is muddying up the water. You really need to understand CC v5 code and templates in order to answer this question.

Like I said in my original response, $DATA.shipping is not a numeric value, it is a string. It is a formatted string that includes the currency symbol. You cannot do a mathematical compare on a string!

The code should be


{if ({$DATA.shipping}) == "0.00€" }(A Calcular)

{/if}{$DATA.shipping}

And because it is already formatted by the time it gets to the template, the above will only work for the active currency. Additional if else statements can be added to account for other currency supported by the shop

Thanks

/Goober

Link to comment
Share on other sites

I am suggesting a solution that need not anticipate every possible user and their environment, and when the environment does change, the solution need not change to accommodate it.

PHP provides floatval() and intval() which attempts to extract what looks like a number from a string. But they are not as versatile as I had hoped. PanKBoy shows the situation that some currencies have their symbol in front. It seems floatval() doesn't like that. So, we remove anything that is not a digit and compare the result to zero.

{if floatval(preg_replace("/[^0-9]/","",$DATA.shipping)) == 0 }(A Calcular){else}{$DATA.shipping}{/if}

Link to comment
Share on other sites

Guest PanKBoy

bsmither thank you for the alternative, but i change the EURO symbol to the right and it worked perfectly, thank you all! ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...