コード例 #1
0
  @SuppressWarnings("unchecked")
  @ResponseBody
  @RequestMapping(value = "/order/updateFreeItem.ajax", method = RequestMethod.POST)
  public ResponseEntity<byte[]> updateFreeItem(
      HttpServletRequest request, @RequestParam(value = "body") String body) throws Exception {

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Updating free item: " + body);
    }

    Map<String, Object> model = new HashMap<String, Object>();

    try {
      // Extract request parameters
      Map<String, Object> params = (Map<String, Object>) jsonUtils.deserialize(body);
      String discountId = (String) params.get("discountId");
      String freeItem = (String) params.get("freeItem");

      HttpSession session = request.getSession(true);
      String orderId = (String) session.getAttribute("orderid");
      Order order = null;
      if (orderId != null) {
        order = orderRepository.findByOrderId(orderId);
        if (order != null) {
          OrderDiscount orderDiscount = order.getOrderDiscount(discountId);
          if (orderDiscount != null) {
            orderDiscount.setSelectedFreeItem(freeItem);
            order = orderRepository.save(order);
          }

          // Update order restaurant id session attribute if any items present
          if (order.getOrderItems().size() > 0) {
            session.setAttribute("orderrestaurantid", order.getRestaurantId());
            session.setAttribute("orderrestauranturl", order.getRestaurant().getUrl());
          } else {
            session.removeAttribute("orderrestaurantid");
            session.removeAttribute("orderrestauranturl");
          }

          // Update can checkout status of order
          session.setAttribute("cancheckout", order.getCanCheckout());
        }
      }

      model.put("success", true);
      model.put("order", order);
    } catch (Exception ex) {
      LOGGER.error("", ex);
      model.put("success", false);
      model.put("message", ex.getMessage());
    }
    return buildOrderResponse(model);
  }
コード例 #2
0
  @Test
  public void setTest() {
    Random r = new Random();
    int[] vals = {r.nextInt(500), r.nextInt(500), r.nextInt(500)};
    int i = 0;
    Order o = orderDiscount.set(vals[i++], vals[i++], String.valueOf(vals[i]));
    assertNotNull(o.getId());
    i = 0;

    assertEquals(vals[i++], orderDiscount.getDiscountTaxFree(), 0);
    assertEquals(vals[i++], orderDiscount.getDiscountTaxIncluded(), 0);
    assertEquals(String.valueOf(vals[i]), orderDiscount.getPromotionalCode());

    orderDiscount =
        orderDiscount.setDiscountTaxFree(1).setDiscountTaxIncluded(1).setPromotionalCode("p");
    assertEquals(1, orderDiscount.getDiscountTaxFree(), 0);
    assertEquals(1, orderDiscount.getDiscountTaxIncluded(), 0);
    assertEquals("p", orderDiscount.getPromotionalCode());
  }
コード例 #3
0
 @Test
 public void initTest() {
   assertNull(orderDiscount.getPromotionalCode());
   assertEquals(-1, orderDiscount.getDiscountTaxFree(), 0);
   assertEquals(-1, orderDiscount.getDiscountTaxIncluded(), 0);
 }