Claudia M Posted June 11, 2021 Share Posted June 11, 2021 In the email templates is there any way to only show the discount field if a discount is given? Otherwise the discount field does not show. Thanks in advance for any and all help Claudia Link to comment Share on other sites More sharing options...
bsmither Posted June 11, 2021 Share Posted June 11, 2021 Please switch the editor to Source mode. Find: <tr> <td> </td> <td> Discount:</td> <td> {$DATA.discount}</td> </tr> Change to: <tr> <td>{if !empty($DATA.discount)} {/if}</td> <td>{if !empty($DATA.discount)} Discount:{/if}</td> <td>{if !empty($DATA.discount)} {$DATA.discount}{/if}</td> </tr> Do NOT do this for HTML: {if !empty($DATA.discount)} <tr> <td> </td> <td> Discount:</td> <td> {$DATA.discount}</td> </tr> {/if} Be sure to also do the Plain Text tab. The reason not to wrap the whole <tr> table row in the {if} test is because the editor really insists that nothing exist* between the parts of the table structure. So, we must therefore blank the cell's contents, which should then collapse the row into a thin gap. *CubeCart adds HTML comments, the only thing the editor allows to exist between the parts of the table structure, to the {foreach} tags when loading the template into the editor, and strips them off when saving from the editor. Link to comment Share on other sites More sharing options...
Claudia M Posted June 11, 2021 Author Share Posted June 11, 2021 Thanks Brian .... You know I was going to {if} the whole row but something told me to ask you first. Glad I did!!! Claudia Link to comment Share on other sites More sharing options...
Claudia M Posted June 12, 2021 Author Share Posted June 12, 2021 I tried your code with a test order and the admin order received email. The discount and tax fields are still showing. Here's my code. <tr> <td style="font-family: Verdana,arial, helvetica, sans-serif; font-size: 13px; color: #153643; padding-bottom:3px; padding-left:10px;">{if !empty($DATA.discount)} {/if}</td> <td style="font-family: Verdana,arial, helvetica, sans-serif; font-size: 13px; color: #153643; padding-bottom:3px; padding-left:10px;">{if !empty($DATA.discount)} Discount:{/if}</td> <td style="font-family: Verdana,arial, helvetica, sans-serif; font-size: 13px; color: #153643; padding-bottom:3px; padding-left:10px;">{if !empty($DATA.discount)} {$DATA.discount}{/if}</td> </tr> <tr> <td style="font-family: Verdana,arial, helvetica, sans-serif; font-size: 13px; color: #153643; padding-bottom:3px; padding-left:10px;">{if !empty($DATA.total_tax)} {/if}</td> <td style="font-family: Verdana,arial, helvetica, sans-serif; font-size: 13px; color: #153643; padding-bottom:3px; padding-left:10px;">{if !empty($DATA.total_tax)}Tax:{/if}</td> <td style="font-family: Verdana,arial, helvetica, sans-serif; font-size: 13px; color: #153643; padding-bottom:3px; padding-left:10px;">{if !empty($DATA.total_tax)}{/if}</td> </tr> Link to comment Share on other sites More sharing options...
bsmither Posted June 12, 2021 Share Posted June 12, 2021 If the fields are still showing, then it would be my thought that $DATA.discount and $DATA.total_tax are not empty. Please try to view the actual sent email in its HTML form. You may be able to get this by viewing the email in the admin, Email Log. Then asking your browser to show you the source of the colorbox overlay. (Or ask your email application to show you the source.) A recent email in my system shows this: <tr> <td> </td> <td>Discount:</td> <td>$0.00</td> </tr> Please observe that $DATA.discount is not empty. First, PHP considers integer 0, string "0", string "0.0", and the empty string "" as empty. This is a string "0.00" - not empty - and there is the currency symbol - not empty. We will either need to absolutely blank out the values held in these array elements in the core code (maybe via a snippet), or somehow deal with processing the string "$0.00" (or whatever currency format is in use) before testing for emptiness. Looking for a solution. If you are positive that your emails will contain this specific format, "$0.00", we can make the test for that: {if $DATA.total_tax neq '$0.00'} (I really thought CubeCart sent nothing if it was a zero value. Never actually noticed.) Link to comment Share on other sites More sharing options...
bsmither Posted June 12, 2021 Share Posted June 12, 2021 I tested with this: {if !empty($DATA.discount|filter_var:FILTER_SANITIZE_NUMBER_INT|intval)} Link to comment Share on other sites More sharing options...
Claudia M Posted June 13, 2021 Author Share Posted June 13, 2021 I looked at the view source of the email I sent and it does show the discount as $0.00 <tr> <td> </td> <td> Discount:</td> <td> $0.00</td> </tr> I sent another test email this time using CubeCart's stock email, basically. It didn't show the tax field. Here's the code from British Order Confirmation: <!--{foreach from=$TAXES item=tax}--> <tr> <td> </td> <td>{$tax.tax_name}: ({$tax.tax_percent}%)</td> <td>{$tax.tax_amount}</td> </tr> <!--{/foreach}--> Link to comment Share on other sites More sharing options...
bsmither Posted June 13, 2021 Share Posted June 13, 2021 Ok, in this case, $TAXES may exist, but it will be an array with zero elements - that is, nothing was found in the tax tables that could apply, but the array might have been established in the core code ready to accept a tax on this, and a tax on that, and another tax on something else. It's just that nothing was found to apply a tax to. So, Smarty's {foreach} didn't find any elements in $TAXES and so didn't work through the looped code. That's not the same as $tax_total, a distinct value (known as a 'scalar' value), which we can say is not empty. And, I do not see in CubeCart's list of "macros' that $DATA.total_tax is available. So, did you edit the core code to make it available? Link to comment Share on other sites More sharing options...
Claudia M Posted June 13, 2021 Author Share Posted June 13, 2021 I probably did add total.tax. If I made that change I don't remember Link to comment Share on other sites More sharing options...
Claudia M Posted June 14, 2021 Author Share Posted June 14, 2021 The only time I would use the discount is if I gave a shipping overage discount to an ebay or Etsy customer when I created the order. They do not receive emails thru CubeCart, but I receive the emails, and I like to use the discount field (shipping refund) for my records - it keeps the offsite fees correct. I just don't think it looks very professional to send a CubeCart customer an order confirmation email with discount $0.00. It's like you're saying "hey I give discounts you just aren't gettting one". Link to comment Share on other sites More sharing options...
bsmither Posted June 14, 2021 Share Posted June 14, 2021 Hehe. Link to comment Share on other sites More sharing options...
Claudia M Posted June 14, 2021 Author Share Posted June 14, 2021 <!--{foreach from=$TAXES item=tax}--> <tr> <td> </td> <td>{$tax.tax_name}: ({$tax.tax_percent}%)</td> <td>{$tax.tax_amount}</td> </tr> <!--{/foreach}--> Why is this commented out, but still doesn't show the tax fields if there are no taxes Link to comment Share on other sites More sharing options...
bsmither Posted June 14, 2021 Share Posted June 14, 2021 CubeCart adds the HTML comment tags to the {foreach} tags when assigning the content to the CKEditor textarea, and then removes the HTML comment tags from the {foreach} tags when processing the editor's content POSTed back by the browser. The reason is that CKEditor is very particular about a web page structure. One of the editor's structural enforcement is that there cannot be any content between the parts of a table structure. The {foreach} tags are disallowed content. Unless that content happens to be HTML comments. So, again, CubeCart removes those HTML comment tags from the enclosed {foreach} tags before databasing the content. Smarty will see and process the {foreach} tags, iterating through the $TAXES array. However, if the array is empty (no applicable taxes found), or if $TAXES was never assigned anything at all, there is nothing to iterate and so, no table rows. Let's re-examine this: Do NOT do this for HTML: {if !empty($DATA.discount)} <tr> <td> </td> <td> Discount:</td> <td> {$DATA.discount}</td> </tr> {/if} There are Smarty {if} tags between parts of a table structure. CKEditor won't like this and try to "fix" it. We could add HTML comment tags and surround the {if} tags (considering that CubeCart only looks for {foreach}). The end result would have empty HTML comments both before and after the table row, or a single empty HTML comment where the row would be (if $DATA.discount was truly empty). Link to comment Share on other sites More sharing options...
Claudia M Posted June 15, 2021 Author Share Posted June 15, 2021 What would the above look like and would it hide the discount row unless there was a discount? Link to comment Share on other sites More sharing options...
bsmither Posted June 15, 2021 Share Posted June 15, 2021 Wrapping the {if} tags in HTML comments would look like: Template Code: <!--{if !empty($DATA.discount)}--> <tr> <td> </td> <td> Discount:</td> <td> {$DATA.discount}</td> </tr> <!--{/if}--> Final HTML should $DATA.discount be empty: <!----> <!----> But earlier we learned that $DATA.discount is never empty - having a currency symbol, etc. But also as mentioned earlier, we can massage the string to be empty if it really is by using: {if !empty($DATA.discount|filter_var:FILTER_SANITIZE_NUMBER_INT|intval)} Link to comment Share on other sites More sharing options...
Claudia M Posted June 15, 2021 Author Share Posted June 15, 2021 So you think this may work to hide the discount rows unless used? Template Code: <!--{if !empty($DATA.discount|filter_var:FILTER_SANITIZE_NUMBER_INT|intval)}--> <tr> <td> </td> <td> Discount:</td> <td> {$DATA.discount}</td> </tr> <!--{/if}--> But it would still show this in the email if discount is not used? Final HTML should $DATA.discount be empty: <!----> <!----> Link to comment Share on other sites More sharing options...
bsmither Posted June 15, 2021 Share Posted June 15, 2021 Yes. Yes. But when viewing the email, the HTML comment tags do not show - just like HTML comment tags do not show in a web page. Link to comment Share on other sites More sharing options...
Claudia M Posted June 15, 2021 Author Share Posted June 15, 2021 Ok thank you Brian ... I'll give this a go ASAP!!!! Link to comment Share on other sites More sharing options...
bsmither Posted June 15, 2021 Share Posted June 15, 2021 I am currently creating a bug report where CubeCart is deleting all HTML comment tags in the POSTed email template content. This is not desirable. As such, you will not see: <!----> <!----> in the final HTML. (Still, you will not see the unwanted Discount row.) Link to comment Share on other sites More sharing options...
Claudia M Posted June 15, 2021 Author Share Posted June 15, 2021 Will this change the code you gave me if they fix the bug? Link to comment Share on other sites More sharing options...
bsmither Posted June 15, 2021 Share Posted June 15, 2021 No. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.