Ejemplo n.º 1
0
 private static PagesInfo buildPages(
     List<Product> products,
     int productsPerPage,
     int currentPage,
     String pname,
     String cname,
     HttpServletRequest request)
     throws UnsupportedEncodingException {
   List<String> out = new ArrayList<>();
   for (int i = 0; i < ProductPrepareService.getPageCount(products, productsPerPage); i++) {
     out.add(CatalogPrepareService.getCatalogLinkPage(pname, cname, i + 1, request));
   }
   return new PagesInfo(out, currentPage);
 }
Ejemplo n.º 2
0
  public ModelAndView getProductByCatalogNew(
      WebRequest webRequest,
      HttpServletRequest request,
      HttpServletResponse response,
      String selected,
      String level1,
      int page,
      ModelMap model)
      throws Exception {
    Template tmpl = Template.getTemplate(request);
    model.addAttribute("template", tmpl);
    List<Catalog> catalogs = catalogService.getCatalogList();
    PreparedCatalogList prepCatalogList =
        catalogPrepareService.prepareCatalogList(catalogs, selected);
    model.addAttribute("prepCatalogList", prepCatalogList);

    int id = catalogService.getIdByName(selected);
    Map<String, String> params = getQueryParameters(request);
    int on_page = attributeService.getOnPage(params, tmpl);
    Integer price_order = attributeService.getPriceOrder(params, tmpl);
    List<Product> Allproducts = null;
    if (params.size() == 0) {
      logger.debug("entered");
      Allproducts = productService.getProductsByCatalog(id);
    } else Allproducts = productService.getProductsByParams(id, params, price_order);
    logger.debug("getProductByCatalogNew " + Allproducts.size());
    Map<Filter, List<Filter_variant>> filters = attributeService.getAttrsByCatalog(id, request);
    model.addAttribute("filterBox", new FilterBox(filters, request));

    ProductFilter productFilter = new ProductFilter();
    productFilter.setProducts(Allproducts);
    List<Product> productsForPage = productFilter.getProductsForPage(false, page - 1, on_page);
    if (productsForPage.size() == 0) {
      productsForPage = productFilter.getProductsForPage(false, 0, on_page);
      page = 1;
    }
    productsForPage = productService.getProductsInfo(productsForPage);
    model.addAttribute("products", productsForPage);

    int pages = ProductPrepareService.getPageCount(Allproducts, on_page);
    if (pages > 1) {
      model.addAttribute(
          "pages", buildPages(Allproducts, on_page, page, level1, selected, request));
    }
    return new ModelAndView("shop", model);
  }