implement personalized suggestions
This commit is contained in:
parent
82dacef4c0
commit
bb4aa79243
|
@ -74,11 +74,11 @@ public class ShopArticleController {
|
|||
|
||||
Article article = articleRepository.findArticleById(id);
|
||||
|
||||
// if (!article.isPresent()) {
|
||||
// request.setAttribute("error", "Der Artikel wurde nicht gefunden.");
|
||||
// response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
// return "error/404";
|
||||
// }
|
||||
if (article == null) {
|
||||
request.setAttribute("error", "Der Artikel wurde nicht gefunden.");
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return "error/404";
|
||||
}
|
||||
|
||||
if (setAmount != null && setAmount) {
|
||||
shoppingCart.setArticleCount(article, quantity);
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.hso.ecommerce.controller.shop;
|
|||
|
||||
import org.hso.ecommerce.action.shop.GetRandomArticlesAction;
|
||||
import org.hso.ecommerce.entities.shop.Article;
|
||||
import org.hso.ecommerce.entities.user.User;
|
||||
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -31,7 +32,7 @@ public class ShopIndexController {
|
|||
List<Article> commercialArticles = GetRandomArticlesAction.getRandomArticles(8, articleRepository.getAdvertisedArticles());
|
||||
model.addAttribute("commercialArticles", commercialArticles);
|
||||
|
||||
//check if logged in
|
||||
|
||||
boolean isLoggedIn = false;
|
||||
boolean hasOrders = false;
|
||||
if (session != null && session.getAttribute("id") != null) {
|
||||
|
@ -40,7 +41,8 @@ public class ShopIndexController {
|
|||
}
|
||||
|
||||
if (isLoggedIn) {
|
||||
List<Article> suggestedArticles = articleRepository.getLastOrderedArticles("4");
|
||||
List<Article> suggestedArticles = articleRepository.getLastOrderedArticles();
|
||||
suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0,3) : suggestedArticles; //only latest 4 articles
|
||||
if (suggestedArticles.size() > 0) {
|
||||
model.addAttribute("suggestedArticles", suggestedArticles);
|
||||
hasOrders = true;
|
||||
|
|
|
@ -13,16 +13,16 @@ import java.util.Optional;
|
|||
@Repository
|
||||
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||
|
||||
@Query("Select a FROM Article a where a.id = :articleId")
|
||||
@Query("SELECT a FROM Article a WHERE a.id = :articleId")
|
||||
Article findArticleById(@Param("articleId") long articleId);
|
||||
|
||||
|
||||
@Query("SELECT a from Article a join a.related ao where ao.should_be_advertised = true")
|
||||
@Query("SELECT a FROM Article a JOIN a.related ao WHERE ao.should_be_advertised = true")
|
||||
List<Article> getAdvertisedArticles();
|
||||
|
||||
|
||||
@Query("SELECT c FROM User c WHERE c.email = :quantity")
|
||||
List<Article> getLastOrderedArticles(@Param("quantity") String quantity);
|
||||
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
||||
List<Article> getLastOrderedArticles();
|
||||
|
||||
|
||||
}
|
||||
|
|
Reference in New Issue