Compare commits

..

No commits in common. "037f1ff671d247f1911a49fb6a147aaaff424059" and "624ade203263b032061210e3ba7bd9ed77f46616" have entirely different histories.

6 changed files with 16 additions and 67 deletions

View File

@ -37,7 +37,6 @@ public class ShopArticleController {
@GetMapping("/{id}") @GetMapping("/{id}")
public String shopArticlesById(Model model, public String shopArticlesById(Model model,
@RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart,
@PathVariable("id") Long id, @PathVariable("id") Long id,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response HttpServletResponse response
@ -53,14 +52,15 @@ public class ShopArticleController {
} }
model.addAttribute("article", article); model.addAttribute("article", article);
int inStock = warehouseBookingPositionSlotEntryRepository if (warehouseBookingPositionSlotEntryRepository
.getByArticle(id) .getByArticle(id)
.stream() .stream()
.mapToInt(e -> e.newSumSlot) .mapToInt(e -> e.newSumSlot)
.sum(); .sum() > 0) { //check if in Stock
model.addAttribute("inStock", true);
model.addAttribute("inStock", Math.min(inStock, 10)); } else {
model.addAttribute("inCart", shoppingCart.getArticleCount(article)); model.addAttribute("inStock", false);
}
List<Article> commercialArticles = GetRandomArticlesAction.getRandomArticles(3, articleRepository.getAdvertisedArticles()); //get 3 advertised Articles List<Article> commercialArticles = GetRandomArticlesAction.getRandomArticles(3, articleRepository.getAdvertisedArticles()); //get 3 advertised Articles
model.addAttribute("commercialArticles", commercialArticles); model.addAttribute("commercialArticles", commercialArticles);
@ -78,7 +78,7 @@ public class ShopArticleController {
@RequestParam(value = "set_amount", required = false) Boolean setAmount, @RequestParam(value = "set_amount", required = false) Boolean setAmount,
@RequestParam("fastcheckout") Boolean fastcheckout @RequestParam("fastcheckout") Boolean fastcheckout
) { ) {
Article article = articleRepository.findById(id).orElse(null); Article article = articleRepository.findArticleById(id);
if (article == null) { if (article == null) {
request.setAttribute("error", "Der Artikel wurde nicht gefunden."); request.setAttribute("error", "Der Artikel wurde nicht gefunden.");

View File

@ -57,27 +57,13 @@ public class ShopCheckoutController {
CheckoutListTotals totals = new CheckoutListTotals(); CheckoutListTotals totals = new CheckoutListTotals();
ArrayList<CheckoutListItem> items = new ArrayList<>(); ArrayList<CheckoutListItem> items = new ArrayList<>();
boolean inValid = false;
for (ShoppingCart.ShoppingCartItem item : shoppingCart.getItems()) { for (ShoppingCart.ShoppingCartItem item : shoppingCart.getItems()) {
Article article = articleRepository.findById(item.getArticleId()).get(); Article article = articleRepository.findById(item.getArticleId()).get();
int inStock = wbeseRepo
.getByArticle(item.getArticleId())
.stream()
.mapToInt(e -> e.newSumSlot)
.sum();
totals.addItem(article, item.getAmount()); totals.addItem(article, item.getAmount());
items.add(new CheckoutListItem(item.getAmount(), Math.min(inStock, 10), article)); items.add(new CheckoutListItem(item.getAmount(), article));
if (item.getAmount() > inStock) {
inValid = true;
}
} }
request.setAttribute("inValid", inValid);
request.setAttribute("checkoutItems", items); request.setAttribute("checkoutItems", items);
request.setAttribute("checkoutTotals", totals); request.setAttribute("checkoutTotals", totals);
@ -101,13 +87,11 @@ public class ShopCheckoutController {
public int amount; public int amount;
public Article article; public Article article;
public int total; public int total;
public int inStock;
public CheckoutListItem(int amount, int inStock, Article article) { public CheckoutListItem(int amount, Article article) {
this.amount = amount; this.amount = amount;
this.article = article; this.article = article;
this.total = amount * article.getPriceGross(); this.total = amount * article.getPriceGross();
this.inStock = inStock;
} }
} }

View File

@ -69,16 +69,6 @@ public class ShoppingCart {
items.removeIf(i -> i.getAmount() <= 0); 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 { public static class ShoppingCartItem {
private int amount; private int amount;
private final long articleId; private final long articleId;

View File

@ -380,7 +380,7 @@ button, .button {
/* box-shadow: var(--s-0-secondary); */ /* box-shadow: var(--s-0-secondary); */
} }
button:enabled:active, .button:active { button:active, .button:active {
background-color: var(--c-primary-highlight); background-color: var(--c-primary-highlight);
} }
@ -392,10 +392,6 @@ button,
transition: background-color 0.1s ease-out; transition: background-color 0.1s ease-out;
} }
button:disabled {
filter: grayscale(100%);
}
label { label {
display: block; display: block;
min-width: 10em; min-width: 10em;
@ -765,7 +761,6 @@ input[type="number"]:focus {
.error { .error {
background-color: var(--c-error); background-color: var(--c-error);
color: var(--c-base);
text-align: center; text-align: center;
font-size: var(--u0); font-size: var(--u0);
} }

View File

@ -38,28 +38,17 @@
th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span> th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
</h2> </h2>
<div> <div>
<input type="hidden" name="set_amount" value="true"/>
<label class="nolinebreak">Menge:</label> <label class="nolinebreak">Menge:</label>
<select name="quantity" size="1"> <select name="quantity" size="1">
<option th:if="${inCart > 0}" th:value="${inCart}" th:text="${inCart}" <option th:each="quantity : ${#numbers.sequence(1,10)}"
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:value="${quantity}"
th:text="${quantity}"></option> th:text="${quantity}"></option>
</select> </select>
</div> </div>
<h3 class="no-margin secondarytext" <h3 class="no-margin secondarytext" th:text="${inStock} ? 'AUF LAGER' : 'NICHT AUF LAGER'"></h3>
th:text="${inStock > 0} ? 'AUF LAGER' : 'NICHT AUF LAGER'"></h3> <button class="no-margin secondary" name="fastcheckout" value="false">In den Einkaufswagen
<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>
<button class="no-margin" name="fastcheckout" value="true">Schneller Checkout</button>
</div> </div>
</form> </form>
</div> </div>

View File

@ -58,19 +58,12 @@
<select name="quantity" size="1"> <select name="quantity" size="1">
<option th:value="${item.amount}" th:text="${item.amount}" selected></option> <option th:value="${item.amount}" th:text="${item.amount}" selected></option>
<option value="0">Entfernen</option> <option value="0">Entfernen</option>
<option th:if="${item.inStock > 0}" <option th:each="quantity : ${#numbers.sequence(1,10)}"
th:each="quantity : ${#numbers.sequence(1,item.inStock)}"
th:value="${quantity}" th:value="${quantity}"
th:text="${quantity}"></option> th:text="${quantity}"></option>
</select> </select>
<button class="small">Ändern</button> <button class="small">Ändern</button>
</form> </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> </td>
</tr> </tr>
<th:block> <th:block>
@ -145,9 +138,7 @@ Musterstraße 4
</table> </table>
</div> </div>
<div th:if="${user}"> <div th:if="${user}">
<button class=" no-margin secondary full-width" th:disabled="${inValid}">jetzt kostenpflichtig <button class=" no-margin secondary full-width">jetzt kostenpflichtig bestellen</button>
bestellen
</button>
</div> </div>
<div th:unless="${user}"> <div th:unless="${user}">
<a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und fortfahren.</a> <a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und fortfahren.</a>