Show error if articles are not avail during checkout.
This commit is contained in:
parent
c0ce1e23c3
commit
731f4761fa
@ -68,7 +68,8 @@ public class CreateOrderAction {
|
||||
totalVatCent += article.getVat() * quantity;
|
||||
}
|
||||
|
||||
public Result finish() {
|
||||
|
||||
public Result finish() throws ArticleNotInStockException {
|
||||
CustomerOrder order = createOrder();
|
||||
CustomerPayment payment = createPayment();
|
||||
|
||||
@ -86,7 +87,7 @@ public class CreateOrderAction {
|
||||
);
|
||||
}
|
||||
|
||||
private WarehouseBooking createWarehouseBooking(CustomerOrder order) {
|
||||
private WarehouseBooking createWarehouseBooking(CustomerOrder order) throws ArticleNotInStockException {
|
||||
WarehouseBooking booking = new WarehouseBooking();
|
||||
booking.created = new Timestamp(new Date().getTime());
|
||||
booking.reason = new BookingReason(order);
|
||||
@ -111,6 +112,10 @@ public class CreateOrderAction {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needed > 0) {
|
||||
throw new ArticleNotInStockException(item.article);
|
||||
}
|
||||
}
|
||||
|
||||
return booking;
|
||||
@ -174,4 +179,17 @@ public class CreateOrderAction {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ArticleNotInStockException extends Exception {
|
||||
private Article article;
|
||||
|
||||
public ArticleNotInStockException(Article article) {
|
||||
super("The quantity of article '" + article.title + "' is not in stock.");
|
||||
this.article = article;
|
||||
}
|
||||
|
||||
public Article getArticle() {
|
||||
return article;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ public class ShopCheckoutController {
|
||||
|
||||
@PostMapping("/checkoutFinish")
|
||||
public String shopCheckoutFinish(
|
||||
HttpSession session,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestAttribute(value = "user") User user,
|
||||
@ -132,15 +133,22 @@ public class ShopCheckoutController {
|
||||
action.addArticle(article, item.getAmount(), wbeseRepo.getByArticle(article.id));
|
||||
}
|
||||
|
||||
CreateOrderAction.Result result = action.finish();
|
||||
CreateOrderAction.Result result = null;
|
||||
try {
|
||||
result = action.finish();
|
||||
EnableTrackingAction.addTrackingInfo(result.customerOrder);
|
||||
|
||||
EnableTrackingAction.addTrackingInfo(result.customerOrder);
|
||||
customerOderRepository.save(result.customerOrder);
|
||||
bookingRepository.saveAll(result.bookings);
|
||||
warehouseBookingRepository.save(result.warehouseBooking);
|
||||
|
||||
customerOderRepository.save(result.customerOrder);
|
||||
bookingRepository.saveAll(result.bookings);
|
||||
warehouseBookingRepository.save(result.warehouseBooking);
|
||||
shoppingCart.clear();
|
||||
|
||||
} catch (CreateOrderAction.ArticleNotInStockException e) {
|
||||
request.setAttribute("error", "Der Artikel '" + e.getArticle().title + "' ist leider nicht mehr in ausreichender Menge verfügbar. Bitte passen Sie die Artikelmenge an.");
|
||||
return shopCheckout(session, request, shoppingCart);
|
||||
}
|
||||
|
||||
shoppingCart.clear();
|
||||
|
||||
return "shop/checkoutFinish";
|
||||
}
|
||||
|
Reference in New Issue
Block a user