/** * Add the selected items into cart. * * @param request The HttpServletRequest that contains the items to be added. * @return The name of the JSP page that is to be directed to. */ public String add(HttpServletRequest request) { Cart myCart = (Cart) request.getSession().getAttribute("cart"); HashMap<String, HashMap<StockType, LinkedList<Stock>>> itemsAlreadyInCart = new HashMap<String, HashMap<StockType, LinkedList<Stock>>>(); String[] itemsToAdd = request.getParameterValues("addToCart"); if (itemsToAdd == null) { request.setAttribute("cartSize", myCart.getCartSize()); return "cart.jsp"; } for (String item : itemsToAdd) { // if item is not in cart. LinkedList<Stock> inCart = itemIsInCart(item, myCart.getItems()); if (inCart == null) { System.out.println(item); myCart.addToCart(getItem(item)); } else { HashMap<StockType, LinkedList<Stock>> duplicated = new HashMap<StockType, LinkedList<Stock>>(); duplicated.put(getItem(item).getType(), inCart); itemsAlreadyInCart.put(item, duplicated); } } request.setAttribute("cartSize", myCart.getCartSize()); request.setAttribute("totalCost", getTotal(myCart)); request.setAttribute("alreadyInCartSize", itemsAlreadyInCart.size()); request.setAttribute("alreadyInCart", itemsAlreadyInCart); return "cart.jsp"; }
/** * Check out the items that the user had added into cart and display the list of items without * check boxes. Users cannot remove items on this page. * * @param request The HttpServletRequest * @return The next page to be directed to. */ public String checkout(HttpServletRequest request) { Cart myCart = (Cart) request.getSession().getAttribute("cart"); float totalPrice = 0; for (Stock s : myCart.getItems()) { totalPrice += s.getPrice(); } request.setAttribute("totalCost", totalPrice); return "confirm.jsp"; }
public Cart getSpecificCart(int index) { init(); if (index < 0) { index = 0; } if (index > (data.size() - 1)) { index = data.size() - 1; } Cart obj = data.get(index); Long id = obj.getId(); return cartRepository.findOne(id); }
/** * @param request * @param response * @throws ServletException * @throws IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int cartId = Integer.parseInt(request.getParameter("cartId")); Cart cart = new Cart(); boolean check = cart.deleteCartItem(cartId); if (check) { response.sendRedirect("userCart.jsp"); } else { response.sendRedirect("userCart.jsp"); } }
/** * Remove the selected items in cart. * * @param request The HttpServletRequest that contains the items to be removed. * @return The name of the JSP page to be directed to. */ public String remove(HttpServletRequest request) { Cart myCart = (Cart) request.getSession().getAttribute("cart"); LinkedList<Stock> itemsInCart = myCart.getItems(); String[] itemsToRemove = request.getParameterValues("removeFromCart"); if (itemsToRemove == null) return "cart.jsp"; for (String item : itemsToRemove) { itemsInCart.remove(getItem(item)); } request.setAttribute("cartSize", myCart.getCartSize()); request.setAttribute("totalCost", getTotal(myCart)); return "cart.jsp"; }
public void setShippingCity(Cart obj, int index) { String shippingCity = "shippingCity_" + index; if (shippingCity.length() > 100) { shippingCity = shippingCity.substring(0, 100); } obj.setShippingCity(shippingCity); }
public void setShippingState(Cart obj, int index) { String shippingState = "shippingState_" + index; if (shippingState.length() > 50) { shippingState = shippingState.substring(0, 50); } obj.setShippingState(shippingState); }
public void setShippingAddress2(Cart obj, int index) { String shippingAddress2 = "shippingAddress2_" + index; if (shippingAddress2.length() > 200) { shippingAddress2 = shippingAddress2.substring(0, 200); } obj.setShippingAddress2(shippingAddress2); }
public void setShippingAddress1(Cart obj, int index) { String shippingAddress1 = "shippingAddress1_" + index; if (shippingAddress1.length() > 200) { shippingAddress1 = shippingAddress1.substring(0, 200); } obj.setShippingAddress1(shippingAddress1); }
/** * Get total cost of purchase in cart. * * @param myCart The cart. * @return The total cost. */ public float getTotal(Cart myCart) { float total = 0; for (Stock s : myCart.getItems()) { total += s.getPrice(); } return total; }
public void setShippingZipcode(Cart obj, int index) { String shippingZipcode = "shipping_" + index; if (shippingZipcode.length() > 10) { shippingZipcode = shippingZipcode.substring(0, 10); } obj.setShippingZipcode(shippingZipcode); }
public boolean getCartContent(String[] tabCommands) { if (userId == null) { setFailLog("getcartcontent : Not Login"); return (false); } else { lastResult = cart.getCartContentByIdUser(userId); return (true); } }
@Override public void reserveInventory(Cart cart) { for (Item item : cart.getItems()) { try { inventorySystem.reserve(item.sku, item.quantity); } catch (InsufficientInventoryException insufficientInventoryException) { throw new OrderException( "Insufficient inventory for item " + item.sku, insufficientInventoryException); } } }
public boolean pay(String[] tabCommands) { if (userId == null) { setFailLog("pay : Not Login"); return (false); } else { if (!cart.pay(userId)) { setFailLog("empty cart"); return (false); } else { return (true); } } }
@Override public void putGoodsToCart() { try { for (int j = Helper.getRandomIntegerInRange(1, 3); j < 4; j++) { int goodNumber = Helper.getRandomIntegerInRange(0, 4); Good good = Good.fixedListOfGoods.get(goodNumber); cart.addGoods(good); TimeUnit.MILLISECONDS.sleep(Helper.getRandomIntegerInRange(minPutTime, maxPutTime)); System.out.println( "Customer " + customerNumber + " has put " + good.getName() + " into the cart"); } readyToCheckout = true; } catch (InterruptedException e) { e.printStackTrace(); } }
public boolean addToCart(String[] tabCommands) { if ((userId == null)) { setFailLog("addtocart : not login"); return (false); } else if (tabCommands.length < 3) { setFailLog("addtocart : invalid command line"); return (false); } else { try { Integer.parseInt(tabCommands[1]); Integer.parseInt(tabCommands[2]); } catch (NumberFormatException e) { setFailLog("addtocart : invalid Id"); return (false); } if (cart.addContentToCart(userId, tabCommands[1], tabCommands[2], product)) { return (true); } else { failLog = "addtocart : sql error"; return (false); } } }
public static boolean isCustomerAddressSet(Cart cart) { return cart.getShippingAddress() != null; }
public Cart getRandomCart() { init(); Cart obj = data.get(rnd.nextInt(data.size())); Long id = obj.getId(); return cartRepository.findOne(id); }
@Override public boolean chargeCard(PaymentDetails paymentDetails, Cart cart) { return paymentGateway.charge( cart.getBillingTotal(), cart.getCustomerName(), paymentDetails.cardNumber); }
public void removeProductFromCart(Product product) { cart.remove(product); }
public void addItemToCart(Product product, int quantity) { commerce.model.refactored.Item item = new commerce.model.refactored.Item(product, quantity); cart.addItem(item); }
public zzaCU setTotalPrice(String s) { zzaCU.zzaCR = s; return this; }
public void addProductToCart(Product product) { cart.add(product); }
public zzaCU setCurrencyCode(String s) { zzaCU.zzaCS = s; return this; }
/** * Goes trough the table auction and checks which auctions are over. If the auction is over, finds * all bids for that auction, selects the highest bid and sends winning message, also sends to all * other users message that auction is over. */ public static void checkAuctionOutcome() { // Declaring list of all auctions. List<Auction> auctions = finder.all(); // Declaring variable that represents current date. Date currentDate = new Date(); // Going trough all auctions. for (int i = 0; i < auctions.size(); i++) { // Declaring variable that represents auction ending date. Date auctionEndingDate = auctions.get(i).endingDate; // Checking if the auction is active and if the auction ending date is before current date. if (auctions.get(i).isActive && auctionEndingDate.before(currentDate)) { // Finding all auction bids. List<Bid> bids = Bid.getAuctionBids(auctions.get(i)); // Declaring variable that represents highest bid. Bid highestBid = bids.get(0); // Declaring string variable that represents winning message. String winningMessage = "Congratulations!!! You won bitBay auction for item #" + auctions.get(i).product.id + " - " + auctions.get(i).product.name + ".\n\r \n\r To proceed with transaction please contact: " + auctions.get(i).product.user.email; // Declaring and saving winning message. Message message = new Message( CommonHelpers.serviceUser(), highestBid.user, "Auction Winning", winningMessage); message.save(); // Sending SMS notification to auction winner. String sms = "Congratulations!!! You won bitBay auction for item #" + auctions.get(i).product.id + " - " + auctions.get(i).product.name + ". " + "This product has been sent to your cart"; if (highestBid.user.phoneNumber != null) { SmsHelper.sendSms(sms, highestBid.user.phoneNumber); } // After user won on auction create new cart if user don't have one, and put auction item to // his cart Cart cart = Cart.findCartByUser(highestBid.user); if (cart == null) { Cart newCart = new Cart(); newCart.user = highestBid.user; newCart.save(); CartItem cartItem = new CartItem(auctions.get(i).product, highestBid.user, newCart); cartItem.save(); } else { CartItem cartItem = new CartItem(auctions.get(i).product, highestBid.user, cart); cartItem.save(); } // Declaring string set that will contain emails of all users that have not had highest bid. Set<String> bidUsers = new HashSet<>(); // Adding all user emails to the set. for (int j = 0; j < bids.size(); j++) { bidUsers.add(bids.get(j).user.email); } // Removing email of highest bit user from the set. bidUsers.remove(highestBid.user.email); // Declaring string variable that represents losing message. String losingMessage = "Biding for item #" + auctions.get(i).product.id + " - " + auctions.get(i).product.name + " is over.\n\r \n\r We are sorry to inform you that your bid was not enough."; // Declaring iterator list of all user emails. Iterator<String> iter = bidUsers.iterator(); // Going trough all emails and sending message. while (iter.hasNext()) { User receiver = User.getUserByEmail(iter.next()); Message msg = new Message(CommonHelpers.serviceUser(), receiver, "Auction results", losingMessage); msg.save(); } // Setting auction status to inactive. auctions.get(i).isActive = false; auctions.get(i).update(); } } }
// 1 进入团购的页面 @Action( value = "nextGrouponitemPage", interceptorRefs = {@InterceptorRef(value = "userActionStack")}, results = { @Result(name = SUCCESS, location = "/userPages/grouponitem.jsp"), @Result(name = "over", location = "/userPages/cart.jsp") }) public String nextGrouponitemPage() { User findUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user"); // if() Groupon find = grouponService.getGroupon(groupon.getId()); Grouponitem grouponitem = new Grouponitem(); grouponitem.setId(page); grouponitem.setGroupon(find); Grouponitem findItem = grouponService.next(grouponitem); // 如果没有找到,那么意味着查询已经结束 if (findItem == null) { double fee = 0.0; int num = 0; List<Cart> result = new ArrayList<Cart>(); List<Cartitem> items = cartService.getGrouponitemsByUser(findUser.getId(), find.getId()); for (int i = 0; i < items.size(); i++) { Cartitem cartitem = items.get(i); num += cartitem.getNum(); if (cartitem.getSalesBook() == null) { if (cartitem.getBook().getDiscount() == 0.0) { cartitem.getBook().setDiscount(ConstantUtil.NEWBOOKDISCOUNT); } SalesBook newbookSalesBook = salesBookService.getSalesBookByIsbnSeller( cartitem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT); float discount = ConstantUtil.NEWBOOKDISCOUNT; if (newbookSalesBook != null && newbookSalesBook.getDiscount() != null) { discount = newbookSalesBook.getDiscount(); } fee += cartitem.getNum() * Math.round(cartitem.getBook().getPrice() * discount * 10) / 10d; } else { fee += cartitem.getNum() * cartitem.getSalesBook().getPrice(); } Cart cart = cartitem.getCart(); Cart findCart = getCartByList(cart.getId(), result); if (findCart == null) { Cart cartResult = new Cart(); cartResult.setId(cart.getId()); cartResult.setSeller(cart.getSeller()); cartResult.setCartitems(new HashSet()); cartResult.setTotalFee(cart.getTotalFee()); cartResult.setUser(cart.getUser()); cartResult.getCartitems().add(cartitem); cartitem.setCart(cartResult); result.add(cartResult); } else { findCart.getCartitems().add(cartitem); cartitem.setCart(findCart); } } System.out.println(result.size()); ActionContext.getContext().getValueStack().set("carts", result); ActionContext.getContext().getValueStack().set("num", num); ActionContext.getContext().getValueStack().set("fee", Math.round(fee * 10) / 10d); return "over"; } Book book = bookService.getBookByIsbn(findItem.getBook().getIsbn()); // 如果没有拿到数据,则返回空 ServiceArea serviceArea = findUser.getSchool().getServiceArea(); // 如果找到了,查看新书供应商有没有此数据,如果没有,那么就给新书供应商加进去 SalesBook newbookSalesBook = salesBookService.getSalesBookByIsbnSeller( findItem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT); Seller seller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT); SalesBook model = salesBookService.getSalesBookByIsbnSeller(findItem.getBook().getIsbn(), seller.getId()); float bookDiscount; if (newbookSalesBook == null) { newbookSalesBook = new SalesBook(); newbookSalesBook.setSeller(seller); newbookSalesBook.setBook(book); newbookSalesBook.setTitle(book.getTitle()); newbookSalesBook.setAuthor(book.getAuthor()); newbookSalesBook.setStandardPrice(book.getPrice()); newbookSalesBook.setPublisher(book.getPublisher()); newbookSalesBook.setImage(book.getImage()); newbookSalesBook.setBigImage(book.getBigImage()); salesBookService.save(newbookSalesBook); } if (model == null) { model = newbookSalesBook; } if (newbookSalesBook.getDiscount() == null) { bookDiscount = ConstantUtil.NEWBOOKDISCOUNT; } else { bookDiscount = newbookSalesBook.getDiscount(); } ActionContext.getContext().getValueStack().set("bookDiscount", bookDiscount); newbookSalesBook.setDiscount(bookDiscount); newbookSalesBook.setPrice( Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d); newbookSalesBook.setNum(999); SalesBook salesBook = newbookSalesBook; School findSchool = findUser.getSchool(); List<SellerBean> sellerBeans = salesBookService.getSellerBeans( newbookSalesBook.getBook().getIsbn(), findSchool.getServiceArea().getId()); int totalNum = cartService.getGrouponitemsByUser(findUser.getId(), find.getId()).size(); ActionContext.getContext().getValueStack().set("sellerBeans", sellerBeans); ActionContext.getContext().getValueStack().set("item", findItem); Seller newBookSeller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT); ActionContext.getContext().getValueStack().set("totalNum", totalNum); ActionContext.getContext().getValueStack().set("model", model); ActionContext.getContext().getValueStack().set("newBookSeller", newBookSeller); ActionContext.getContext() .getValueStack() .set("price", Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d); // 获得这个学校所有的团购项目 return SUCCESS; }
@Override public String toString() { return "CartDetailId [Carrello=" + cart.getIdCart() + ", progressivo=" + progressivo + "]"; }
@Override public double apply(Cart cart, double price) { return cart.getCount() * price * discount / 100; }