Created
October 16, 2013 13:36
-
-
Save JumboLove/7007826 to your computer and use it in GitHub Desktop.
Get Sale Price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns a formatted string of the sale price in USD or an empty string if there is no sale price | |
function getSalePrice(product : Product) { | |
var priceTable : ProductPriceModel = product.getPriceModel(); | |
var currentPrice : Money = priceTable.getPrice(); | |
var standardPrice : Money = priceTable.getPriceBookPrice(dw.system.Site.getCurrent().getCustomPreferenceValue('listPriceDefault')); | |
if(standardPrice.available && currentPrice.available && standardPrice.compareTo(currentPrice) == 1){ | |
// Product is on sale | |
return currentPrice.toNumberString() === "N/A" ? "" : currentPrice.toNumberString(); | |
} else { | |
// Product is not on sale | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment