Created
April 14, 2019 17:39
-
-
Save gugell/913f2d1f76f8bcaaab8615caac343159 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
var total:Double { | |
var result = self.subtotal | |
if let coupon = self.coupon, coupon.isactive{ | |
//percentage | |
//fixed | |
let sums = products.filter{$0.discounted}.compactMap({ ($0.price ?? 0.0) * Double($0.qty ?? 0) }) | |
let totalDiscounted = sums.reduce(0.0, +) | |
if coupon.type == "fixed"{ | |
result -= (totalDiscounted - coupon.value) | |
}else if coupon.type == "percentage"{ | |
result -= totalDiscounted*coupon.value | |
} | |
} | |
return result | |
} | |
let discount:String?{ | |
var result:String = nil | |
if let coupon = self.coupon , coupon.isactive{ | |
result = coupon.type == "fixed" ? "\(coupon.value) $" : "\(coupon.value) %%" | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment