Example #1
0
 // 删除购物车项
 @RequestMapping(value = "/cart/ajaxDeleteCartItem.jspx")
 public void ajaxDeleteCartItem(
     Long cartItemId, HttpServletRequest request, HttpServletResponse response, ModelMap model)
     throws JSONException {
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   }
   CartItem cartItem = cartItemMng.findById(cartItemId);
   Cart cart = cartItem.getCart();
   PopularityGroup popularityGroup = cartItem.getPopularityGroup();
   cart.getItems().remove(cartItem);
   cartMng.update(cart);
   if (cart != null && popularityGroup != null) {
     List<CartItem> list = cartItemMng.getlist(cart.getId(), popularityGroup.getId());
     list.remove(cartItem);
     for (CartItem item : list) {
       item.setPopularityGroup(null);
       cartItemMng.updateByUpdater(item);
     }
     update(cart, popularityGroup);
   }
   log.info("delete to cartItem cartItemId={}", cartItemId);
   json.put("status", 1);
   ResponseUtils.renderJson(response, json.toString());
 }
Example #2
0
 // 加入购物车
 @RequestMapping(value = "/cart/add_popularity.jspx")
 public void addToPopularity(
     Long popularityId, HttpServletRequest request, HttpServletResponse response, ModelMap model)
     throws JSONException {
   Website web = SiteUtils.getWeb(request);
   // 0:未登录;1:正常,商品总数;2:数量过大,最大数量;
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   } else {
     if (getinventory(popularityId)) {
       Cart cart = null;
       for (Product product : popularityGroupMng.findById(popularityId).getProducts()) {
         cart =
             shoppingSvc.collectAddToCart(
                 product, null, popularityId, 1, true, member, web, request, response);
       }
       popularityItemMng.save(cart, popularityId);
       json.put("status", 1);
       json.put("count", cart.getTotalItems());
     } else {
       json.put("status", 2);
       json.put("error", "库存不足");
     }
   }
   ResponseUtils.renderJson(response, json.toString());
 }
Example #3
0
  // 选择收货地址、付款方式、配送方式
  @RequestMapping(value = "/cart/checkout_shipping.jspx")
  public String shippingInput(
      Long[] cart2Checkbox,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model) {
    Website web = SiteUtils.getWeb(request);
    ShopMember member = MemberThread.get();
    if (member == null) {
      return "redirect:../login.jspx";
    }
    Cart cart = shoppingSvc.getCart(member.getId());
    if (cart == null) {
      return "redirect:shopping_cart.jspx";
    }
    List<PopularityItem> popularityItems = null;
    Double popularityPrice = 0.0;
    if (cart != null) {
      popularityItems = popularityItemMng.getlist(cart.getId(), null);
      for (PopularityItem popularityItem : popularityItems) {
        popularityPrice +=
            popularityItem.getPopularityGroup().getPrivilege() * popularityItem.getCount();
      }
    }

    Set<CartItem> items = getItems(cart2Checkbox, cart);
    Double price = getPrice(items);
    // 配送方式
    List<Shipping> splist = shippingMng.getList(web.getId(), true);
    // 会员地址
    List<ShopMemberAddress> smalist = shopMemberAddressMng.getList(member.getId());
    // 所处省份
    List<Address> plist = addressMng.getListById(null);
    // 付款方式
    List<Payment> paylist = paymentMng.getList((long) 1, true);
    model.addAttribute(
        "memberCouponlist", memberCouponMng.getList(member.getId(), new BigDecimal(price)));
    model.addAttribute("items", getItems(cart2Checkbox, cart));
    model.addAttribute("smalist", smalist);
    model.addAttribute("plist", plist);
    model.addAttribute("paylist", paylist);
    model.addAttribute("splist", splist);
    model.addAttribute("popularityPrice", popularityPrice);
    ShopFrontHelper.setCommonData(request, model, web, 1);
    return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request, CHECKOUT_SHIPPING));
  }
Example #4
0
 // 加入购物车
 @RequestMapping(value = "/cart/add_orderItem.jspx")
 public void addToCart(
     Long productId,
     Integer productAmount,
     Long fashId,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws JSONException {
   Website web = SiteUtils.getWeb(request);
   // 0:未登录;1:正常,商品总数;2:数量过大,最大数量;
   ShopMember member = MemberThread.get();
   JSONObject json = new JSONObject();
   if (member == null) {
     json.put("status", 0);
   } else {
     Product product = productMng.findById(productId);
     if (fashId == null) {
       if (productAmount > product.getStockCount()) {
         json.put("status", 2);
         json.put("error", "库存不足");
       } else {
         Cart cart =
             shoppingSvc.collectAddToCart(
                 product, fashId, null, productAmount, true, member, web, request, response);
         json.put("status", 1);
         json.put("count", cart.getTotalItems());
       }
     } else {
       ProductFashion productFashion = productFashionMng.findById(fashId);
       if (productAmount > productFashion.getStockCount()) {
         json.put("status", 2);
         json.put("error", productFashion.getAttitude() + "库存不足");
       } else {
         Cart cart =
             shoppingSvc.collectAddToCart(
                 product, fashId, null, productAmount, true, member, web, request, response);
         json.put("status", 1);
         json.put("count", cart.getTotalItems());
       }
     }
   }
   log.info("add to cart productId={}, count={}", productId, productAmount);
   ResponseUtils.renderJson(response, json.toString());
 }
Example #5
0
 public void update(Cart cart, PopularityGroup popularityGroup) {
   if (popularityGroup != null) {
     PopularityItem popularityItem =
         popularityItemMng.findById(cart.getId(), popularityGroup.getId());
     if (popularityItem != null) {
       popularityItemMng.deleteById(popularityItem.getId());
     }
   }
 }
Example #6
0
 public java.util.Set<com.jspgou.cms.entity.CartItem> getItems(Long[] cart2Checkbox, Cart cart) {
   Set<CartItem> items = new HashSet<CartItem>();
   if (cart2Checkbox != null) {
     for (Long id : cart2Checkbox) {
       items.add(cartItemMng.findById(id));
     }
   } else {
     items = cart.getItems();
   }
   return items;
 }
Example #7
0
 // 购物车
 @RequestMapping(value = "/cart/shopping_cart.jspx")
 public String shoppingCart(
     String backUrl, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
   ShopMember member = MemberThread.get();
   if (member == null) {
     return "redirect:../login.jspx";
   }
   Website web = SiteUtils.getWeb(request);
   Cart cart = shoppingSvc.getCart(member, request, response);
   List<PopularityItem> popularityItems = null;
   if (cart != null) {
     popularityItems = popularityItemMng.getlist(cart.getId(), null);
   }
   model.addAttribute("cart", cart);
   if (!StringUtils.isBlank(backUrl)) {
     model.addAttribute(BACK_URL, backUrl);
   }
   model.addAttribute("popularityItems", popularityItems);
   ShopFrontHelper.setCommonData(request, model, web, 1);
   return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request, SHOPPING_CART));
 }