fix only show ordered Articles from specific Customer
This commit is contained in:
parent
7f95cef13b
commit
a62e3e8a63
|
@ -34,14 +34,13 @@ public class ShopIndexController {
|
||||||
|
|
||||||
boolean isLoggedIn = false;
|
boolean isLoggedIn = false;
|
||||||
boolean hasOrders = false;
|
boolean hasOrders = false;
|
||||||
|
|
||||||
if (session != null && session.getAttribute("userId") != null) {
|
if (session != null && session.getAttribute("userId") != null) {
|
||||||
long userId = (long) session.getAttribute("userId");
|
long userId = (long) session.getAttribute("userId");
|
||||||
isLoggedIn = true;
|
isLoggedIn = true;
|
||||||
}
|
|
||||||
|
|
||||||
if (isLoggedIn) {
|
List<Article> suggestedArticles = articleRepository.getOrderedArticles(userId);
|
||||||
List<Article> suggestedArticles = articleRepository.getOrderedArticles();
|
suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0, 4) : suggestedArticles; //only latest 4 articles
|
||||||
suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0,4) : suggestedArticles; //only latest 4 articles
|
|
||||||
if (suggestedArticles.size() > 0) {
|
if (suggestedArticles.size() > 0) {
|
||||||
model.addAttribute("suggestedArticles", suggestedArticles);
|
model.addAttribute("suggestedArticles", suggestedArticles);
|
||||||
hasOrders = true;
|
hasOrders = true;
|
||||||
|
|
|
@ -19,8 +19,8 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||||
List<Article> getAdvertisedArticles();
|
List<Article> getAdvertisedArticles();
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a WHERE c.id = :customerId ORDER BY co.id DESC")
|
||||||
List<Article> getOrderedArticles();
|
List<Article> getOrderedArticles(long customerId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
<h1>Angebote</h1>
|
<h1>Angebote</h1>
|
||||||
<script th:src="@{/js/back.js}"></script>
|
<script th:src="@{/js/back.js}"></script>
|
||||||
<div class="back" data-group="shop" data-name="Zurück zur Startseite." data-insert="false"></div>
|
<div class="back" data-group="shop" data-name="Zurück zur Startseite." data-insert="false"></div>
|
||||||
<div class='grid m base shadow'>
|
<div th:if="${commercialArticles.size() == 0}">
|
||||||
|
<h1>Momentan gibt es keine Angebote</h1>
|
||||||
|
</div>
|
||||||
|
<div class='grid m base shadow' th:if="${commercialArticles.size() != 0}">
|
||||||
<section th:each="article: ${commercialArticles}">
|
<section th:each="article: ${commercialArticles}">
|
||||||
<a th:href="@{/shop/articles/{id}(id=${article.id})}" class="section">
|
<a th:href="@{/shop/articles/{id}(id=${article.id})}" class="section">
|
||||||
|
|
||||||
|
|
Reference in New Issue