@RequestMapping(value = "/view-image.html") public ModelAndView viewImages(HttpServletRequest request, HttpServletResponse response) { // request.setAttribute(RequestConstants.DECORATOR,"blank"); ModelAndView mv = getModelAndView("catalog/viewImages"); Integer productId = ServletRequestUtils.getIntParameter(request, "pid", 0); Product product = productManager.getById(productId); if (product == null) { return notFoundPage(request, response); } mv.addObject("product", product); // 获取产品媒体 List<ProductMedia> productMoreImages = productMediaManager.findProductMediaByProductIdAndType( productId, CatalogConstants.PRODUCT_MEDIA_TYPE_MORE_IMAGE); // 添加上产品默认图片 mv.addObject("productMoreImages", productMoreImages); // 获取目录导航 // 获取目录code CatalogHelper catalogHelper = CatalogHelper.getInstance(); String categoryCode = request.getParameter("cc"); Category category = null; if (StringUtils.isNotBlank(categoryCode)) { category = catalogHelper.getCategoryByCode4Front(Constants.CATEGORY_TYPE_CATALOG, categoryCode); } // 指定的code不存在相应的目录时,直接获取该产品的主目录 if (category == null) { Category mainCategory = product.getMainCategory(); if (mainCategory != null) category = catalogHelper.getCategoryById4Front( Constants.CATEGORY_TYPE_CATALOG, mainCategory.getCategoryId()); // 缓存不存在该目录的,直接获取数据库的目录 if (category == null) category = mainCategory; } List<Category> navigatorCategorys = null; // 当目录为空的就不显示该目录相关信息,只显示产品数据 if (category != null) { // 获取产品导航目录 navigatorCategorys = category.getNavigatorCategorys(); } mv.addObject("navigatorCategorys", navigatorCategorys); return mv; }
public ModelAndView review(HttpServletRequest request, HttpServletResponse response) { String uri = request.getRequestURI(); if (RequestContext.isAnonymousUser() && !ConfigUtil.getInstance().getIsAllowAnonymousReview()) { SessionUtil.setAttribute(request.getSession(), "HAS_ERRORS", Boolean.TRUE); saveMessage(Message.error("common.loginConfirm")); return new ModelAndView(new RedirectView(uri + "#review")); } Integer pIdcId[] = CatalogHelper.getInstance().getProductIdByUri(uri); Integer productId = pIdcId[0]; String message = request.getParameter("message"); String customerName = request.getParameter("customerName"); String subject = request.getParameter("subject"); Integer productRate = Integer.parseInt(request.getParameter("productRate").split("_")[1]); ; String attrRates[] = request.getParameterValues("rateItems"); if (productId.intValue() != 0 && productId.intValue() != 0) { ProductReview productReview = new ProductReview(); productReview.setProductId(productId); productReview.setSubject(subject); productReview.setMessage(message); if (RequestContext.isAnonymousUser()) { // TODO 设置匿名用户对象,系统必须存在Id为-2的匿名用户 productReview.setReviewUserId(Constants.USERID_ANONYMOUS); } else { productReview.setReviewUserId(RequestContext.getCurrentUserId()); } productReview.setCustomerName(customerName); productReview.setRate(productRate); productReview.setRemoteIp(request.getRemoteAddr()); productReview.setStore(ConfigUtil.getInstance().getStore()); if (attrRates == null) attrRates = new String[] {}; productMainManager.saveProductReviewAction(productReview, attrRates); saveMessage(Message.info("product.addReview.success")); } return new ModelAndView(new RedirectView(uri + "#review")); }
// @RequestMapping(value={"/*_p{pId}_{cId}.html","/*_p{pId}.html",}) @RequestMapping(value = "/product/*.html") public ModelAndView defaultAction(HttpServletRequest request, HttpServletResponse response) { Store store = ConfigUtil.getInstance().getStore(); String uri = request.getRequestURI(); request.setAttribute("uri", uri); CatalogHelper catalogHelper = CatalogHelper.getInstance(); Integer pIdcId[] = catalogHelper.getProductIdByUri(uri); Integer productId = pIdcId[0]; Integer categoryId = pIdcId[1]; // 查找产品 Product product = productManager.getById(productId); // 没有找到相应产品或草稿状态的不能访问,直接进入找不到或已删除页面 if (product == null) { return notFoundPage(request, response); } // 获取导航目录 // 获取产品主目录 Category category = null; if (categoryId != null) { Category temp_category = catalogHelper.getCategoryById4Front(Constants.CATEGORY_TYPE_CATALOG, categoryId); if (temp_category != null) { Set<ProductCategory> productCategorySet = product.getProductCategorys(); for (ProductCategory productCategory : productCategorySet) { if (productCategory.getCategory().getCatalogId().intValue() == store.getCatalogId() && productCategory.getCategory().getId().intValue() == temp_category.getId()) { category = temp_category; break; } } } } // 指定目录不存在的直接获取产品主目录 if (category == null) { Category mainCategory = product.getMainCategory(); // 任何时候都从所以目录中查找,因为产品任何状态在前台都是可见的, /* if(mainCategory!=null) category=catalogHelper.getCategoryById4Front(Constants.CATEGORY_TYPE_CATALOG,mainCategory.getCategoryId());*/ // 缓存不存在该目录的,直接获取数据库的目录 if (category == null && mainCategory != null) { category = catalogHelper.getCategoryById4Front( Constants.CATEGORY_TYPE_CATALOG, mainCategory.getCategoryId()); } } // 检查请求的URI内的产品名是否正确,不正确的重定向到正确的URI // 目录已删除的不需要检查 if (category != null) { String productUri = catalogHelper.getProductUrl(product, store.getCatalogId(), category.getCategoryId()); try { if (!URLDecoder.decode(uri, "UTF-8").equals(request.getContextPath() + productUri)) { return new ModelAndView(new RedirectView301(productUri, true)); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if (category == null) { return notFoundPage(request, response); } List<Category> navigatorCategorys = null; // 当目录为空的就不显示该目录相关信息,只显示产品数据 if (category != null) { // 获取产品导航目录 navigatorCategorys = category.getNavigatorCategorys(); } // 获取产品媒体 // // List<ProductMedia>productMoreImages=productMediaManager.findProductMediaByProductIdAndType(product.getProductId(), CatalogConstants.PRODUCT_MEDIA_TYPE_MORE_IMAGE); List<ProductMedia> productMoreImages = new ArrayList<ProductMedia>(product.getDefaultProductSku().getProductMedias()); List<ProductMediaUp> productMoreImagesUp = productMediaUpManager.findProductMediaByProductIdAndType( product.getProductId(), CatalogConstants.PRODUCT_MEDIA_TYPE_MORE_IMAGE); // 产品媒体附件 List<ProductMedia> productaccessories = productMediaManager.findProductMediaByProductIdAndType( product.getProductId(), CatalogConstants.PRODUCT_MEDIA_TYPE_ACCESSORIES); // 获取自定义属性组及值 List<ProductAttGroup> productAttGroups = productMainManager.findAttGroupAndProductAttrValueByProduct(product); // 获取库存信息 // Inventory inventory=inventoryService.getInventoryBySku(product.getDefaultProductSkuId()); Inventory inventory = product.getDefaultProductSku().getInventory(); ModelAndView modelAndView = null; // 激活状态下完整显示产品 String defaultView = "catalog/productTemplate"; if (product.getStatus().intValue() == Constants.STATUS_ACTIVE.intValue()) { String view = this.getTemplatePath(defaultView, product.getTemplatePath()); modelAndView = getModelAndView(view); JSONObject jsonProductModel = new JSONObject(); // 是否变种产品,变种产品时,显示带有sku选项 if (product.getProductKind().intValue() == CatalogConstants.PRODUCT_KIND_VARIATION.intValue()) { // SkuOption及值 Map<SkuOption, List<SkuOptionValue>> productSkuOptionAndValues = productMainManager.findSkuOptionsByProduct(productId); modelAndView.addObject("productSkuOptionAndValues", productSkuOptionAndValues); // 变种信息 List<ProductSku> productSkuList = productSkuManager.findActiveProductSkusByProductId(productId); // 为productSku设置促销价 promoService.appendPromoInfo(productSkuList); JSONArray jsonOptionAndSkuList = new JSONArray(); JSONArray jsonSkuOptionList = new JSONArray(); JSONArray jsonSkuOptionNameList = new JSONArray(); // 获取shu产品相关信息 for (ProductSku productSku : productSkuList) { // 设置价格显示方式 catalogHelper.setPriceViewType(productSku); // 获取sku的选项及值,SkuOption及SkuOptionValue Map<SkuOption, SkuOptionValue> skuOptionAndValues = productMainManager.findSkuOptionAndValuesByProductSku(productSku.getId()); Set<Entry<SkuOption, SkuOptionValue>> skuOptionAndValue = skuOptionAndValues.entrySet(); JSONArray temp_jsonSkuData = new JSONArray(); for (Entry<SkuOption, SkuOptionValue> entry : skuOptionAndValue) { temp_jsonSkuData.add(entry.getValue().getSkuOptionValueId()); } temp_jsonSkuData.add(productSku.getId()); jsonOptionAndSkuList.add(temp_jsonSkuData); if (jsonSkuOptionList.size() < 1) { Set<SkuOption> skuOptions = skuOptionAndValues.keySet(); for (SkuOption skuOption : skuOptions) { jsonSkuOptionList.add(skuOption.getId()); jsonSkuOptionNameList.add(skuOption.getSkuOptionName()); } } } jsonProductModel.put("jsonOptionAndSkuList", jsonOptionAndSkuList); jsonProductModel.put("jsonSkuOptionList", jsonSkuOptionList); jsonProductModel.put("jsonSkuOptionNameList", jsonSkuOptionNameList); jsonProductModel.put("jsonProduct", productJSONData(product, productSkuList)); modelAndView.addObject("jsonProductModel", jsonProductModel.toString()); modelAndView.addObject("jsonProduct", productJSONData(product, productSkuList)); } else { // 普通产品或产品包 // 为productSku设置促销价 ProductSku defaultProductSku = product.getDefaultProductSku(); promoService.appendPromoInfo(defaultProductSku); // 设置价格显示方式 catalogHelper.setPriceViewType(defaultProductSku); } } else if (product.getStatus().intValue() == Constants.STATUS_INACTIVE) { // 非激活状态下,简单显示产品 modelAndView = getModelAndView(defaultView); } else { response.setStatus(HttpServletResponse.SC_GONE); return getModelAndView("catalog/categoryErrorPage"); } // 获取产品评论项 List<ProductRateItem> productRateItemList = productRateItemManager.findProductRateItemsByProductType(product.getProductTypeId()); modelAndView.addObject("productRateItemList", productRateItemList); // 获取产品附件组,及相应的附件项 List<Map.Entry<AccessoryGroup, List<Accessory>>> productAccessoryList = productManager.getProductAccessoryMap(product.getProductId()); modelAndView.addObject("productAccessoryList", productAccessoryList); // 获取产品对应的促销信息(待性能提升) Vector<PRule> rules = pruleManager.getCartPromotionRules(); List<PRule> productRules = new ArrayList<PRule>(); for (PRule prule : rules) { short conditionOperator = prule.getConditionOperator(); if (prule.getRuleType().equals(PromoRule.PROMOTION_TYPE_CATALOGPROMOTION)) { conditionOperator += 2; } ConditionMaintainHandler conditionMaintainManager = new ConditionMaintainHandler(conditionOperator, prule.getConditions()); if (conditionMaintainManager.run(product)) { productRules.add(prule); } } modelAndView.addObject("productRules", productRules); modelAndView.addObject("product", product); modelAndView.addObject("category", category); modelAndView.addObject("navigatorCategorys", navigatorCategorys); modelAndView.addObject("productMoreImages", productMoreImages); modelAndView.addObject("productMoreImagesUp", productMoreImagesUp); modelAndView.addObject("productaccessories", productaccessories); modelAndView.addObject("productAttGroups", productAttGroups); modelAndView.addObject("inventory", inventory); return modelAndView; }