Skip to content

Instantly share code, notes, and snippets.

@JumboLove
Created October 16, 2013 13:36
Show Gist options
  • Save JumboLove/7007826 to your computer and use it in GitHub Desktop.
Save JumboLove/7007826 to your computer and use it in GitHub Desktop.
Get Sale Price
// 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