Jump to content

Adding a <br /> in notification email (New Order Confirmation) with mulitple same products.


-M-

Recommended Posts

Hi all,

 

I have a small cosmetic problem, which I couldn't solve by my own.

 

Here is an example part of the coding I use in my 'New Order Confirmation' notification email:

 

   {else if $product.groupname eq "SSL certificaten"}
       <strong>Bestellings categorie: {$product.groupname}</strong>
       <br />
       Bestelling: {$product.name} €{$product.productrealprice} EUR {$product.articlecode}
       <br />
       {foreach from=$product.configoptions item=configoption}
           {$configoption.option}: {$configoption.value}
           <br />
       {/foreach}
       {foreach from=$product.customfields item=customfield}
        	{if $customfield.name eq "CSR code voor uw SSL certificaat" and $customfield.value neq ""}<br /><strong>{$customfield.name|replace:'CSR code voor uw SSL certificaat':'Opgegeven CSR code'}:</strong><br /><small>{$customfield.value|nl2br}<br /></small>
        	{else}{if $customfield.value neq ""}{$customfield.name}: {$customfield.value|nl2br}<br />{/if}{/if}
       {/foreach}

 

This works great when only, in this case, one (1) SSL certificate is being ordered.

 

When a customer places an order for several SSL certificates it will stack them underneath each other without a <br /> between them. Obviously the most simple way would be to add a <br /> at the end of that part, in this case after {/foreach}, but this will mess up the other products I already have in there.

 

Now I want to know if it's possible to create some kind of Smarty rule which adds a <br /> to the last line, if two (2) or more SSL certificates are ordered.

 

If someone can tell me how to pull this of, I would be very happy and I can apply it to another section as well (which suffers from the same issue).

 

FYI: the <br /> should only be applied at the location I need it.

 

Thanks in advance.

 

Yes, I know it sounds silly, but redoing the complete notification email (again) is a lot of work. Therefor I am looking for some kind of Smarty solution which can be applied to this.

Link to comment
Share on other sites

one possible way might be to use the PHP function of substr_count - that counts how many times a given string is used within a variable.

 

in a Smarty context for an email template, this could be used as...

 

{assign counter substr_count($order_items,'SSL')}

so that would create a new smarty variable, $counter, that would count how many times the phrase 'SSL' is in the $order_items variable... and then you can use it in an if statement...

 

{if $counter gt 1}<br />{/if}

this will only work in your case if you have a consistent word in your order output that is used a fixed number of times (once, twice etc) per SSL product - if not, you might have to check if the variable contains the strings 'product x' and 'product y' to trigger the break return... difficult to explain without seeing the email output, but hopefully what i've said makes some sense and will help! :)

Link to comment
Share on other sites

Thanks brian!

 

Well I gave it a go and it worked. However I still now end up with an extra space behind the last one. LOL. :)

In other words, it will have the same result as just adding a <br /> at the end.

 

I guess I have to do it the hard way; as in re-check everything and move/replace/add breaks elsewhere.

 

Anyways thanks for your time anyways. At least I learned something new again. :)

 

Regards

 

//edit

 

Nevermind. I got a better idea. I will create a rule to hide the <br /> at the last position if the product is a SSL certificate. That should work also. :))

Edited by MvdL1979
Link to comment
Share on other sites

i'm glad you found a solution! :idea:

 

just to potentially correct my previous code for others in the future - you might not need the {assign} step in the process as you can probably (though untested!) just use substr_count directly in the {if} statement

 

{if substr_count($order_items,'SSL') gt 1}<br />{/if}

anyway, I shouldn't really post code before lunch - if there are multiple certs, the above is always going to be true so is of little help for your situation! :)

 

I can see ways around that to make it work, but sometimes using more complicated code isn't the better solution... if you can hide the last BR, then problem solved.

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.

  • 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