Last active
November 19, 2017 03:30
-
-
Save noedlm/394f6bfbdfee36594106b3b91e8699e3 to your computer and use it in GitHub Desktop.
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
public numeric function getTotalDiscountForOrder(required array orderProducts) { | |
var totalSavings = 0; | |
for (var product in arguments.orderProducts) { | |
totalSavings += calculateCouponDiscountForProduct(product) * product.quantity; | |
} | |
return totalSavings; | |
} | |
public array function addOrderProductsDiscountedPrice(required array orderProducts) { | |
for (var product in argument.orderProducts) { | |
product["discountedPrice"] = getProductPriceAfterDiscount(product); | |
} | |
return argument.orderProducts; | |
} | |
public numeric function getProductPriceAfterDiscount(required struct product) { | |
return arguments.product.price - calculateCouponDiscountForProduct(arguments.product); | |
} | |
public numeric function calculateCouponDiscountForProduct(required struct product) { | |
var discount = 0; | |
var couponsForProduct = $getCouponsForProduct(arguments.product.id); | |
for(var coupon in couponsForProduct) { | |
discount += arguments.product.price * (coupon.discountpercent/100); | |
} | |
return discount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment