use of org.rembx.jeeshop.order.model.OrderDiscount in project jeeshop by remibantos.
the class PriceEngineImpl method applyEligibleDiscounts.
private Double applyEligibleDiscounts(Order order, Double price) {
double originalPrice = price;
Long userCompletedOrders = orderFinder.countUserCompletedOrders(order.getUser());
List<Discount> userEligibleOrderDiscounts = discountFinder.findEligibleOrderDiscounts(null, userCompletedOrders);
if (userEligibleOrderDiscounts == null) {
return price;
}
if (order.getOrderDiscounts() == null) {
order.setOrderDiscounts(new HashSet<>());
}
for (Discount discount : userEligibleOrderDiscounts) {
if (discount.isEligible(originalPrice)) {
price = discount.processDiscount(price, originalPrice);
order.getOrderDiscounts().add(new OrderDiscount(discount.getId(), discount.getDiscountValue()));
}
}
return price;
}
Aggregations