Exemplo n.º 1
0
  public ModelAndView test(HttpServletRequest request, HttpServletResponse response) {
    System.out.println("Inside Controller****************test:" + productService);
    ModelAndView mv = new ModelAndView("test");

    // check if cart is present
    // session.get
    // System.out.println(productService);
    List<Product> products = productService.getAllEntities();

    Product added = new Product();
    added.setName("new!!!");
    added.setPrice(BigDecimal.valueOf(1200.25));
    added = productService.add(added);

    Customer cust = new Customer();
    cust.setName("dude");
    cust.setEmail("*****@*****.**");
    cust.setCustomerId(cust.getEmail());
    // customerService.add(cust);

    Order order = new Order();
    order.setName("new order");
    order.setCustomer(cust);
    orderService.add(order);
    System.out.println("order " + order.getId());
    mv.addObject("msg", products.size());
    // mv.addObject("added", added.getId());

    return mv;
  }
Exemplo n.º 2
0
  @RequestMapping(path = "/checkOut", method = RequestMethod.POST)
  @ResponseBody
  public String checkOut(@RequestBody Customer customer, HttpSession session) {
    String response = null;
    System.out.print("custName " + customer.getName() + "," + customer.getEmail());
    customer.setCustomerId(customer.getEmail());
    Gson gson = new Gson();
    Order order = new Order();
    // save customer
    // customer=customerService.add(customer);
    /*		List<Customer> currentCustomer=customerService.query("BY_EMAIL",customer.getCustomerId());
    		if (currentCustomer.size()==1) {

    			customer=currentCustomer.get(0);
    		}
    */
    order.setCustomer(customer);
    // hack
    order.setCustomerId(customer.getCustomerId());
    order.setOrderDate(new Date());
    order.setName("ORD_" + customer.getName());
    Cart cart = (Cart) session.getAttribute("CART");
    order.setTotalPrice(cart.getTotalPrice());
    // save customer to session
    session.setAttribute("CUST", customer);
    Iterator<CartItem> cartItems = cart.getItems().iterator();

    while (cartItems.hasNext()) {
      CartItem cartItem = cartItems.next();
      OrderItem orderItem = new OrderItem();
      orderItem.setName(cartItem.getItemName());
      Product product = new Product();
      product.setId(Long.valueOf(cartItem.getItemId()));
      orderItem.setProduct(product);
      orderItem.setQty(cartItem.getQty());
      orderItem.setLineCost(BigDecimal.valueOf(cartItem.getLinePrice()));
      orderItem.setOrder(order);
      order.getItems().add(orderItem);
      cartItems.remove();
    }
    orderService.add(order);
    // clear cart items
    // cart.setItems(new ArrayList<CartItem>());
    cart.setTotalPrice(BigDecimal.ZERO);
    session.setAttribute("CART", cart);
    return gson.toJson(customer);
  }