use of org.rembx.jeeshop.catalog.model.Discount in project jeeshop by remibantos.
the class DiscountsCT method modifyUnknownDiscount_ShouldThrowNotFoundException.
@Test
public void modifyUnknownDiscount_ShouldThrowNotFoundException() {
Discount detachedDiscountToModify = new Discount(9999L);
try {
localService.modify(tester.getSecurityContext(), detachedDiscountToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
}
}
use of org.rembx.jeeshop.catalog.model.Discount 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