Search in sources :

Example 1 with OrderDiscount

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;
}
Also used : OrderDiscount(org.rembx.jeeshop.order.model.OrderDiscount) Discount(org.rembx.jeeshop.catalog.model.Discount) OrderDiscount(org.rembx.jeeshop.order.model.OrderDiscount)

Aggregations

Discount (org.rembx.jeeshop.catalog.model.Discount)1 OrderDiscount (org.rembx.jeeshop.order.model.OrderDiscount)1