diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java index 9345e83..71a6a96 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java @@ -37,6 +37,7 @@ public class ShopArticleController { @GetMapping("/{id}") public String shopArticlesById(Model model, + @RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart, @PathVariable("id") Long id, HttpServletRequest request, HttpServletResponse response @@ -52,15 +53,14 @@ public class ShopArticleController { } model.addAttribute("article", article); - if (warehouseBookingPositionSlotEntryRepository + int inStock = warehouseBookingPositionSlotEntryRepository .getByArticle(id) .stream() .mapToInt(e -> e.newSumSlot) - .sum() > 0) { //check if in Stock - model.addAttribute("inStock", true); - } else { - model.addAttribute("inStock", false); - } + .sum(); + + model.addAttribute("inStock", Math.min(inStock, 10)); + model.addAttribute("inCart", shoppingCart.getArticleCount(article)); List
commercialArticles = GetRandomArticlesAction.getRandomArticles(3, articleRepository.getAdvertisedArticles()); //get 3 advertised Articles model.addAttribute("commercialArticles", commercialArticles); @@ -78,7 +78,7 @@ public class ShopArticleController { @RequestParam(value = "set_amount", required = false) Boolean setAmount, @RequestParam("fastcheckout") Boolean fastcheckout ) { - Article article = articleRepository.findArticleById(id); + Article article = articleRepository.findById(id).orElse(null); if (article == null) { request.setAttribute("error", "Der Artikel wurde nicht gefunden."); diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java index f90b1ac..112083a 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java @@ -57,13 +57,27 @@ public class ShopCheckoutController { CheckoutListTotals totals = new CheckoutListTotals(); ArrayList items = new ArrayList<>(); + + boolean inValid = false; + for (ShoppingCart.ShoppingCartItem item : shoppingCart.getItems()) { Article article = articleRepository.findById(item.getArticleId()).get(); + int inStock = wbeseRepo + .getByArticle(item.getArticleId()) + .stream() + .mapToInt(e -> e.newSumSlot) + .sum(); + totals.addItem(article, item.getAmount()); - items.add(new CheckoutListItem(item.getAmount(), article)); + items.add(new CheckoutListItem(item.getAmount(), Math.min(inStock, 10), article)); + if (item.getAmount() > inStock) { + inValid = true; + } } + request.setAttribute("inValid", inValid); + request.setAttribute("checkoutItems", items); request.setAttribute("checkoutTotals", totals); @@ -87,11 +101,13 @@ public class ShopCheckoutController { public int amount; public Article article; public int total; + public int inStock; - public CheckoutListItem(int amount, Article article) { + public CheckoutListItem(int amount, int inStock, Article article) { this.amount = amount; this.article = article; this.total = amount * article.getPriceGross(); + this.inStock = inStock; } } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/shop/ShoppingCart.java b/prototype/src/main/java/org/hso/ecommerce/entities/shop/ShoppingCart.java index d059f15..ff47fe2 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/shop/ShoppingCart.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/shop/ShoppingCart.java @@ -69,6 +69,16 @@ public class ShoppingCart { items.removeIf(i -> i.getAmount() <= 0); } + public int getArticleCount(Article article) { + for (ShoppingCartItem i : items) { + if (i.getArticleId() == article.id) { + return i.amount; + } + } + + return 0; + } + public static class ShoppingCartItem { private int amount; private final long articleId; diff --git a/prototype/src/main/resources/static/css/ecom.css b/prototype/src/main/resources/static/css/ecom.css index 2a696d2..d48664c 100644 --- a/prototype/src/main/resources/static/css/ecom.css +++ b/prototype/src/main/resources/static/css/ecom.css @@ -380,7 +380,7 @@ button, .button { /* box-shadow: var(--s-0-secondary); */ } -button:active, .button:active { +button:enabled:active, .button:active { background-color: var(--c-primary-highlight); } @@ -392,6 +392,10 @@ button, transition: background-color 0.1s ease-out; } +button:disabled { + filter: grayscale(100%); +} + label { display: block; min-width: 10em; @@ -761,6 +765,7 @@ input[type="number"]:focus { .error { background-color: var(--c-error); + color: var(--c-base); text-align: center; font-size: var(--u0); } diff --git a/prototype/src/main/resources/templates/shop/articles/id.html b/prototype/src/main/resources/templates/shop/articles/id.html index 00d2c73..1686bef 100644 --- a/prototype/src/main/resources/templates/shop/articles/id.html +++ b/prototype/src/main/resources/templates/shop/articles/id.html @@ -38,17 +38,28 @@ th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"> EUR
+
-

- + + - diff --git a/prototype/src/main/resources/templates/shop/checkout.html b/prototype/src/main/resources/templates/shop/checkout.html index b5aea23..bab984d 100644 --- a/prototype/src/main/resources/templates/shop/checkout.html +++ b/prototype/src/main/resources/templates/shop/checkout.html @@ -58,12 +58,19 @@ + + + + + + Die gewählte Anzahl des Artikels ist leider derzeit nicht lieferbar. @@ -138,7 +145,9 @@ Musterstraße 4
- +
Einloggen und fortfahren.