Пример #1
0
  @RequestMapping(value = "/shop/{id}/cart-next")
  public String next(@PathVariable("id") String shopId, Model model, HttpServletRequest req) {
    List<CartItemVO> cartItems = new ArrayList<CartItemVO>();
    PricingResultVO prices = new PricingResultVO();

    List<CartItemVO> items = cartService.listCartItems(shopId);
    Map<String, Integer> skuMap = new HashMap<String, Integer>();
    for (CartItem item : items) {
      Sku sku = productService.loadSku(item.getProductId(), item.getSkuId());
      if (sku == null) {
        continue;
      }
      CartItemVO itemVO = new CartItemVO();
      BeanUtils.copyProperties(item, itemVO);
      itemVO.setProduct(productService.load(item.getProductId()));
      itemVO.setSku(sku);
      cartItems.add(itemVO);
      skuMap.put(sku.getId(), item.getAmount());
    }
    prices = pricingService.calculate(skuMap, null, null);

    if (cartItems.size() == 0) {
      return "redirect:/shop/" + shopId + "/cart";
    }
    model.addAttribute("cartItems", cartItems);
    model.addAttribute("prices", prices);
    model.addAttribute("shopId", shopId);

    List<AddressVO> addresses = addressService.listUserAddressesVo();
    if (addresses != null && addresses.size() > 0) {
      model.addAttribute("address", addresses.get(0));
    }
    return "cart/next";
  }
Пример #2
0
  @RequestMapping(value = "/shop/{id}/cart")
  public String cart(@PathVariable("id") String shopId, Model model, HttpServletRequest req) {
    List<CartItemVO> cartItems = new ArrayList<CartItemVO>();
    PricingResultVO prices = new PricingResultVO();

    // 购物车没有传递item参数,取用户购物车所有项目
    List<CartItemVO> items = cartService.listCartItems(shopId);
    Map<String, Integer> skuMap = new HashMap<String, Integer>();
    for (CartItem item : items) {
      CartItemVO itemVO = new CartItemVO();
      BeanUtils.copyProperties(item, itemVO);
      itemVO.setProduct(productService.load(item.getProductId()));
      Sku sku = productService.loadSku(item.getProductId(), item.getSkuId());
      if (sku == null) {
        continue;
      }
      itemVO.setSku(sku);
      cartItems.add(itemVO);
      skuMap.put(sku.getId(), item.getAmount());
    }
    prices = pricingService.calculate(skuMap, null, null);
    model.addAttribute("cartItems", cartItems);
    model.addAttribute("prices", prices);

    String nextUrl = "/shop/" + shopId + "/cart-next";
    model.addAttribute("nextUrl", nextUrl);
    return "cart/cart";
  }