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;
|
totalVatCent += article.getVat() * quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result finish() {
|
|
||||||
|
public Result finish() throws ArticleNotInStockException {
|
||||||
CustomerOrder order = createOrder();
|
CustomerOrder order = createOrder();
|
||||||
CustomerPayment payment = createPayment();
|
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();
|
WarehouseBooking booking = new WarehouseBooking();
|
||||||
booking.created = new Timestamp(new Date().getTime());
|
booking.created = new Timestamp(new Date().getTime());
|
||||||
booking.reason = new BookingReason(order);
|
booking.reason = new BookingReason(order);
|
||||||
@ -111,6 +112,10 @@ public class CreateOrderAction {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needed > 0) {
|
||||||
|
throw new ArticleNotInStockException(item.article);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return booking;
|
return booking;
|
||||||
@ -174,4 +179,17 @@ public class CreateOrderAction {
|
|||||||
this.quantity = quantity;
|
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")
|
@PostMapping("/checkoutFinish")
|
||||||
public String shopCheckoutFinish(
|
public String shopCheckoutFinish(
|
||||||
|
HttpSession session,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
@RequestAttribute(value = "user") User user,
|
@RequestAttribute(value = "user") User user,
|
||||||
@ -132,8 +133,9 @@ public class ShopCheckoutController {
|
|||||||
action.addArticle(article, item.getAmount(), wbeseRepo.getByArticle(article.id));
|
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);
|
customerOderRepository.save(result.customerOrder);
|
||||||
@ -142,6 +144,12 @@ public class ShopCheckoutController {
|
|||||||
|
|
||||||
shoppingCart.clear();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return "shop/checkoutFinish";
|
return "shop/checkoutFinish";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user