Esempio n. 1
0
 /** 获取参数组 */
 @RequestMapping(value = "/parameter_groups", method = RequestMethod.GET)
 public @ResponseBody Set<ParameterGroup> parameterGroups(Long id) {
   Set<ParameterGroup> set = null;
   ProductCategory productCategory = productCategoryService.find(id);
   if (productCategory.getParameterGroups() == null
       || productCategory.getParameterGroups().size() <= 0) {
     List<ProductCategory> list = productCategoryService.findParents(productCategory);
     for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
       ProductCategory p = (ProductCategory) iterator.next();
       if (p.getAttributes() != null && p.getParameterGroups().size() > 0) {
         set = p.getParameterGroups();
       }
     }
   } else {
     set = productCategory.getParameterGroups();
   }
   return set;
 }
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    Long productCategoryId =
        FreemarkerUtils.getParameter(PRODUCT_CATEGORY_ID_PARAMETER_NAME, Long.class, params);

    ProductCategory productCategory = productCategoryService.find(productCategoryId);

    List<ProductCategory> productCategories;
    if (productCategoryId != null && productCategory == null) {
      productCategories = new ArrayList<ProductCategory>();
    } else {
      boolean useCache = useCache(env, params);
      String cacheRegion = getCacheRegion(env, params);
      Integer count = getCount(params);
      if (useCache) {
        productCategories = productCategoryService.findParents(productCategory, count, cacheRegion);
      } else {
        productCategories = productCategoryService.findParents(productCategory, count);
      }
    }
    setLocalVariable(VARIABLE_NAME, productCategories, env, body);
  }
Esempio n. 3
0
  /** 点击商品属性获取结果 */
  @RequestMapping(value = "/slist/{productCategoryId}", method = RequestMethod.GET)
  public String slist(
      @PathVariable Long productCategoryId,
      Long brandId,
      Long promotionId,
      Long[] tagIds,
      BigDecimal startPrice,
      BigDecimal endPrice,
      OrderType orderType,
      Boolean isOutOfStock,
      Integer pageNumber,
      Integer pageSize,
      HttpServletRequest request,
      ModelMap model) {
    ProductCategory productCategory = productCategoryService.find(productCategoryId);

    List<ProductCategory> childrenpCategory =
        productCategoryService.findChildrenByParent(productCategoryId);
    if (productCategory == null) {
      throw new ResourceNotFoundException();
    }
    Brand brand = brandService.find(brandId);
    Promotion promotion = promotionService.find(promotionId);
    List<Tag> tags = tagService.findList(tagIds);
    Map<Attribute, String> attributeValue = new HashMap<Attribute, String>();
    if (productCategory != null) {
      Set<Attribute> attributes = productCategory.getAttributes();
      for (Attribute attribute : attributes) {
        String value = request.getParameter("attribute_" + attribute.getId());
        if (StringUtils.isNotEmpty(value) && attribute.getOptions().contains(value)) {
          attributeValue.put(attribute, value);
        }
      }
    }
    Pageable pageable = new Pageable(pageNumber, pageSize);
    model.addAttribute("orderTypes", OrderType.values());
    model.addAttribute("productCategory", productCategory);
    model.addAttribute("childrenpCategory", childrenpCategory);
    model.addAttribute("brand", brand);
    model.addAttribute("promotion", promotion);
    model.addAttribute("tags", tags);
    model.addAttribute("isOutOfStock", isOutOfStock);
    model.addAttribute("attributeValue", attributeValue);
    model.addAttribute("startPrice", startPrice);
    model.addAttribute("endPrice", endPrice);
    model.addAttribute("orderType", orderType);
    model.addAttribute("pageNumber", pageNumber);
    model.addAttribute("pageSize", pageSize);
    model.addAttribute(
        "page",
        productService.findPage(
            productCategory,
            brand,
            promotion,
            tags,
            attributeValue,
            startPrice,
            endPrice,
            true,
            true,
            null,
            false,
            isOutOfStock,
            null,
            orderType,
            pageable));
    return "/gw/product/slist";
  }