Compare commits
2 Commits
624ade2032
...
037f1ff671
Author | SHA1 | Date |
---|---|---|
Jannik | 037f1ff671 | |
CodeSteak | 99896a4f77 |
|
@ -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<Article> 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.");
|
||||
|
|
|
@ -57,12 +57,26 @@ public class ShopCheckoutController {
|
|||
|
||||
CheckoutListTotals totals = new CheckoutListTotals();
|
||||
ArrayList<CheckoutListItem> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -38,17 +38,28 @@
|
|||
th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
|
||||
</h2>
|
||||
<div>
|
||||
<input type="hidden" name="set_amount" value="true"/>
|
||||
<label class="nolinebreak">Menge:</label>
|
||||
<select name="quantity" size="1">
|
||||
<option th:each="quantity : ${#numbers.sequence(1,10)}"
|
||||
<option th:if="${inCart > 0}" th:value="${inCart}" th:text="${inCart}"
|
||||
selected></option>
|
||||
<option th:if="${inCart > 0}" value="0">Entfernen</option>
|
||||
<option th:if="${inStock > 0}" th:each="quantity : ${#numbers.sequence(1,inStock)}"
|
||||
th:value="${quantity}"
|
||||
th:text="${quantity}"></option>
|
||||
</select>
|
||||
</div>
|
||||
<h3 class="no-margin secondarytext" th:text="${inStock} ? 'AUF LAGER' : 'NICHT AUF LAGER'"></h3>
|
||||
<button class="no-margin secondary" name="fastcheckout" value="false">In den Einkaufswagen
|
||||
<h3 class="no-margin secondarytext"
|
||||
th:text="${inStock > 0} ? 'AUF LAGER' : 'NICHT AUF LAGER'"></h3>
|
||||
<button th:if="${inCart == 0}" class="no-margin secondary" name="fastcheckout" value="false"
|
||||
th:disabled="${inStock==0}">In den Einkaufswagen
|
||||
</button>
|
||||
<button th:if="${inCart > 0}" class="no-margin secondary" name="fastcheckout" value="false"
|
||||
th:disabled="${inStock==0}">Anzahl im Einkaufswagen ändern
|
||||
</button>
|
||||
<button class="no-margin" name="fastcheckout" value="true" th:disabled="${inStock==0}">Schneller
|
||||
Checkout
|
||||
</button>
|
||||
<button class="no-margin" name="fastcheckout" value="true">Schneller Checkout</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -58,12 +58,19 @@
|
|||
<select name="quantity" size="1">
|
||||
<option th:value="${item.amount}" th:text="${item.amount}" selected></option>
|
||||
<option value="0">Entfernen</option>
|
||||
<option th:each="quantity : ${#numbers.sequence(1,10)}"
|
||||
<option th:if="${item.inStock > 0}"
|
||||
th:each="quantity : ${#numbers.sequence(1,item.inStock)}"
|
||||
th:value="${quantity}"
|
||||
th:text="${quantity}"></option>
|
||||
</select>
|
||||
<button class="small">Ändern</button>
|
||||
</form>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr th:if="${item.amount > item.inStock}">
|
||||
<td class="error" colspan="4">
|
||||
Die gewählte Anzahl des Artikels ist leider derzeit nicht lieferbar.
|
||||
</td>
|
||||
</tr>
|
||||
<th:block>
|
||||
|
@ -138,7 +145,9 @@ Musterstraße 4
|
|||
</table>
|
||||
</div>
|
||||
<div th:if="${user}">
|
||||
<button class=" no-margin secondary full-width">jetzt kostenpflichtig bestellen</button>
|
||||
<button class=" no-margin secondary full-width" th:disabled="${inValid}">jetzt kostenpflichtig
|
||||
bestellen
|
||||
</button>
|
||||
</div>
|
||||
<div th:unless="${user}">
|
||||
<a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und fortfahren.</a>
|
||||
|
|
Reference in New Issue