I'm trying to create a function in my ItemsKeyMapping.js that will calculate the percentage a customer will be saving on a product. I'm new to javascript and have been using tutorials. This is what I have:
// @property _DiscountPercent calculates the percentage between customers price and MSRP
, _DiscountPercent: function (item)
{
var attributes = item.get('onlinecustomerprice') || ('pricelevel15');
if ((pricelevel15 != 0) && (onlinecustomerprice != 0))
{
DiscountPercent = (1 - pricelevel15 / onlinecustomerprice) * 100;
}
else
{
DiscountPercent = null;
}
return 'DiscountPercent';
}
Anyone out there familar with SCA Mont Blanc that could help me finish this? Thanks.
Try this:
, _DiscountPercent: function (item)
{
var normalPrice= item.get('onlinecustomerprice')
var discountedPrice= item.get('pricelevel15');
var DiscountPercent = null;
if ((discountedPrice > 0) && (normalPrice > 0))
{
DiscountPercent = (1 - discountedPrice / normalPrice) * 100;
}
return DiscountPercent;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.