Jump to content

Show a message only if invoice contain a domain with a specific extension


Recommended Posts

Hi!

 

I want to have in Second and Third Invoice Overdue Notice a message if the invoice contain a renewal .eu domain.
The message must be showed ONLY if it contain a .eu renewal in invoice.

How can I do this?

Many thanks!

Link to comment
Share on other sites

3 hours ago, cosmin said:

I want to have in Second and Third Invoice Overdue Notice a message if the invoice contain a renewal .eu domain.
The message must be showed ONLY if it contain a .eu renewal in invoice.

I do wish you weren't so insistent on using the word "only". :P

the quick way would be to do this...

{if $invoice_html_contents|strstr:'Domain Renewal' and $invoice_html_contents|strstr:'.eu -'}message to .eu customers{/if}

and while I think that should have a very high success rate, it wouldn't be 100% guaranteed - because you could, in theory, have a .com renewal and a .eu registration on the same invoice and it would match the above condition.

the more complicated way, though more accurate, would be to loop through the $invoice_items array and create a variable if there is an .eu domain renewal, then afterwards use an {if} statement to display your custom .eu message...

{foreach $invoice_items as $item}
	{foreach $item as $key => $value}
		{if $key eq "description" and $value|strstr:"Domain Renewal" and $value|strstr:".eu -"}
			{$eudr=true}
		{/if}
	{/foreach}
{/foreach}
{if $eudr eq true}this is an .eu domain renewal{/if}

WHMCS may not like => and will try to change it to => but it should still work.... if it doesn't, fix it be editing the appropriate template in the tblemailtemplates database table.

Link to comment
Share on other sites

Hi and thanks for reply!

Unfortunately is not working, the email are not sent because

Email Sending Failed - Email message rendered empty - please check the email message Smarty markup syntax

I tryed with both of your examples.

Any ideea?

Many thanks!

Link to comment
Share on other sites

6 hours ago, cosmin said:

Unfortunately is not working, the email are not sent because

Email Sending Failed - Email message rendered empty - please check the email message Smarty markup syntax

I tried with both of your examples.

Any idea?

the code itself is fine because I tried it on a v7.4.2 dev before posting and it worked without issue.

the fact that neither solution worked for you, leads me to think it could be one of three things... and taking a look at the activity log (utilities -> logs -> activity log) should tell you exactly where the problem is.

  1. there was an issue copy & pasting the above code into the email template... this can often occur if you just c&p code as it can add unnecessary code to it... e.g if I copy the above code and paste into the template, it actually pastes...
    <pre class="ipsCode prettyprint lang-html prettyprinted"><span class="pln">{foreach $invoice_items as $item}
    	{foreach $item as $key =&gt; $value}
    		{if $key eq "description" and $value|strstr:"Domain Renewal" and $value|strstr:".eu -"}
    			{$eudr=true}
    		{/if}
    	{/foreach}
    {/foreach}
    {if $eudr eq true}this is an .eu domain renewal{/if}</span></pre>

    and now when I attempt to send the email, I get the same error message as you.

    the trick, when entering Smarty code into the template, it to use the HTML button and paste it into the popup window...
    3PtUdWG.png
    C96bm6v.png
    ... or failing that, add it direct to the database table and bypass any annoying changes that WHMCS will make to the code.

  2. another possible issue is that you may be running in the Smarty Security Policy which was introduced in v7 and basically prevents you from using certain PHP functions and modifiers unless you enable them specifically in the policy (by adding them to your configuration.php file) - in this case, it might not like the use of strstr to search the string... if this is occurring, then it should say so in the activity log.

    Smarty Error: Syntax error in template "mailMessage:mailMessage:plaintext" on line 25 "{foreach $invoice_items as $item} {foreach $item as $key => $value} {if $key eq "description" and $value|strstr:"Domain Renewal" and $value|strstr:".eu -"}{$eudr=true}{/if} {/foreach} {/foreach}" modifier 'strstr' not allowed by security setting

     

  3. if you're using an older version of WHMCS, probably pre v7, then it might not like the {$eudr=true} code because it's written for Smarty v3, and if you're using an older version of WHMCS, you'll still be using Smarty v2... so changing that to the code below should fix it... again, if it doesn't like the original code, it should say so in the activity log.

    {assign var="eudr" value=true}

     

Link to comment
Share on other sites

  • 2 weeks later...

Now I realize all invoices with this code lost the html formatting. I put like this in Second Invoice Overdue:

 

 {foreach $invoice_items as $item} {foreach $item as $key =&gt; $value} {if $key eq "description" and $value|strstr:"Reînnoire domeniu" and $value|strstr:".eu -"} {$eudr=true} {/if} {/foreach} {/foreach} {if $eudr eq true}<span style="font-size: small;"><strong><span style="color: #ff0000;">Attention! Bla Bla Bla </span></strong></span>{/if}</p>

 

What is wrong?

Thanks!

Link to comment
Share on other sites

2 hours ago, cosmin said:

Now I realize all invoices with this code lost the html formatting.

that happened with me initially too, but the activity log should give you a clue...

Quote

Smarty Error: Syntax error in template "mailMessage:mailMessage:message" on line 40 "<p>{$signature}<br /> {foreach $invoice_items as $item} {foreach $item as $key => $value} {if $key eq "description" and $value|strstr:"Domain Renewal" and $value|strstr:".eu -"}this is an .ue renewal{/if} {/foreach} {/foreach}</p><!-- message footer start -->" - Unexpected " =", expected one of: "}"

so @ 12:15 on the 5th March, the above email got sent, but without html formatting... then I cleaned up the template code... sent it again at 12:18 and arrived with html formatting.

have you pressed the html button and viewed the source code... i'd bet good money that WHMCS has added some formatting code to the output and it's breaking something.

Link to comment
Share on other sites

Yes, good ideea to look in Activity log :-)

I see this:

Smarty Error: Syntax error in template "mailMessage:mailMessage:message" on line 35 "<p><strong>Furnizor: HOST-AGE.RO GĂZDUIRE WEB SRL<br />C.I.F. RO27953009 <br />Localitate: București <br />Contul (IBAN): RO27BACX0000000585260001 <br />Banca: UniCredit Bank - Sucursala Millennium</strong><br /><br /> <br /> {foreach $invoice_items as $item} {foreach $item as $key => $value} {if $key eq "description" and $value|strstr:"Reînnoire domeniu" and $value|strstr:".eu -"} {$eudr=true} {/if} {/foreach} {/foreach} {if $eudr eq true}<span style="font-size: small;"><strong><span style="color: #ff0000;">Attention! Bla Bla Bla</span></strong></span>{/if}</p>" - Unexpected " =", expected one of: "}"

 

Unfortunately I'm not good to code... where is the problem in this line?

Many thanks!

Link to comment
Share on other sites

4 minutes ago, cosmin said:

Unfortunately I'm not good to code... where is the problem in this line?

open up the html window...

3PtUdWG.png

and you will hopefully see some code that you haven't added (it often doesn't show up in the log).

if you can't see it, copy all the code in the window and send it me as a private message and i'll take a look.

Link to comment
Share on other sites

Hi!

 

Is exactly the code from above

{foreach $invoice_items as $item} {foreach $item as $key =&gt; $value} {if $key eq "description" and $value|strstr:"Reînnoire domeniu" and $value|strstr:".eu -"} {$eudr=true} {/if} {/foreach} {/foreach} {if $eudr eq true}<span style="font-size: small;"><strong><span style="color: #ff0000;">Attention! Bla Bla Bla </span></strong></span>{/if}</p>

 

Thanks!

Link to comment
Share on other sites

57 minutes ago, cosmin said:

Is exactly the code from above

ok, I just tested it on a v7.4.2 and it doesn't like the following line...

{foreach $item as $key =&gt; $value}

WHMCS has converted => to =&gt; and that's what's breaking the code... as I said in a previous post.

On 3/5/2018 at 15:09, brian! said:

WHMCS may not like => and will try to change it to =&gt; but it should still work.... if it doesn't, fix it be editing the appropriate template in the tblemailtemplates database table.

so it will send the email, but break the html formatting... if you fix it, then the html formatting will work correctly. :idea:

are you familiar with using phpmyadmin and editing database tables directly? because that's the only way to fix this - if you try to do it via WHMCS (even using the HTML window), it will just convert => back to =&gt; after you save.

aNGNE5I.png

if you need to use this Smarty code, then you can never edit this template again in the admin area because it will always change it to =&gt; - you'll have to edit in directly in the database.... which is what I often do anyway to avoid WHMCS messing up my code. :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated