Order_ContentTable transformation - nesting conditions

Sharon Parry asked on June 19, 2015 00:33

Having trouble getting the right syntax to display/hide the discount value on the Order_ContentTable.text transformations when the value is 0 (zero).

If an order item has options, it's the options that define the price (ie, the parent SKU has a price of zero). I can hide the relevant value displayed for the other columns in the table with a fairly simple if condition, such as:

{%if(UnitPrice > 0){Units} else {""} %}

But I can't apply the same {%if(condition){do something} else {""} %} to the discount column. I think it's probably because it already has a condition applied (ShoppingCart.IsDiscountApplied), so have been trying all sorts of variations but just can't get it to work. Latest attempt is:

{% (ShoppingCart.IsDiscountApplied) ? ("" + {%if(UnitTotalDiscount > 0){"$" + UnitTotalDiscount.Format("{0:F}")}else{""} %} + "") : ""%}

How can I hide the value of the discount column when it is zero?

PS: I've got the td's in the correct places, and the string I pasted into this box included them, but they're not showing up in the formatted question! so ...

{% (ShoppingCart.IsDiscountApplied) ? ("[opening td]" + {%if(UnitTotalDiscount > 0){"$" + UnitTotalDiscount.Format("{0:F}")}else{""} %} + "[closing td]") : ""%}

Correct Answer

Jan Hermann answered on June 22, 2015 14:57

Hello,

Please try following macro code instead:

{%
if (ShoppingCart.IsDiscountApplied)
{
  if (UnitTotalDiscount > 0) {
    "<td>" + UnitTotalDiscount.Format("{0:F}") + "</td>";
  }
} 
|(identity)GlobalAdministrator%}

It's always better to use standard if-else statement than ?: notation where you need to combine more than one condition.

Best regards,
Jan Hermann

0 votesVote for this answer Unmark Correct answer

Recent Answers


Sharon Parry answered on June 22, 2015 20:10

Ok, thanks Jan, got it!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.