Ejemplo n.º 1
0
 /** Returns */
 public static Call getListProductsUrl(SearchResult<Product> search, Category category) {
   if (search.getCurrentPage() >= search.getTotalPages() - 1) {
     return null;
   }
   // Convert from 0..N-1 to 1..N
   int nextPage = search.getCurrentPage() + 2;
   String categorySlug = "";
   if (category != null) {
     categorySlug = category.getSlug();
   }
   return routes.Categories.listProducts(categorySlug, nextPage);
 }
Ejemplo n.º 2
0
 @With(SaveContext.class)
 public static Result select(String categoryPath, int page) {
   String[] categorySlugs = categoryPath.split("/");
   String categorySlug = categorySlugs[categorySlugs.length - 1];
   Category category = sphere().categories.getBySlug(categorySlug);
   if (category == null) {
     return notFound("Category not found: " + categorySlug);
   }
   FilterExpression categoryFilter = new FilterExpressions.CategoriesOrSubcategories(category);
   SearchRequest<Product> searchRequest = sphere().products.filter(categoryFilter);
   searchRequest = filterBy(searchRequest);
   searchRequest = sortBy(searchRequest);
   searchRequest = paging(searchRequest, page);
   SearchResult<Product> searchResult = searchRequest.fetch();
   if (searchResult.getCount() < 1) {
     flash("info", "No products found");
   }
   return ok(views.html.categories.render(searchResult, category));
 }