Comparing Item Cost to MSRP

Comparing Item Cost to MSRP

This simple example will show you how to compare the item cost to the MSRP and perform conditional messaging to the customer. First we need to explain what we want to accomplish in psuedo logic

If the item has an MSRP (not null == true in Velocity) and the MSRP is less than the Cost then
  display a message to the customer
else
  display a different message to the customer
end

The following if/else statement performs the comparison:

#if ($item.getMSRPAsBigDecimal() && $item.getMSRPAsBigDecimal().compareTo($item.getCostAsBigDecimal()) < 0) 
  Price Break...
#else
  No Price Break...
#end

Now let's put this together into a more complete example where we show the customer the math:

#if ($item.getMSRPAsBigDecimal() && $item.getMSRPAsBigDecimal().compareTo($item.getCostAsBigDecimal()) > 0) 
  <del>$item.getMSRP()</del> <br/>
  - $item.getMSRPPriceBreak() <br/>
  $item.getCost()
#else
  $item.getCost()
#end