예제 #1
0
  @RequestMapping("/shop/")
  public ModelAndView getShopMain(
      WebRequest webRequest,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model)
      throws Exception {
    Template tmpl = Template.getTemplate(request);
    model.addAttribute("template", tmpl);
    List<Catalog> catalogs = catalogService.getCatalogList();
    PreparedCatalogList prepCatalogList = catalogPrepareService.prepareCatalogList(catalogs, "");
    model.addAttribute("prepCatalogList", prepCatalogList);

    List<Product> products = productService.getProducts();
    model.addAttribute("products", products);
    return new ModelAndView("shop", model);
  }
예제 #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);
  }