Example #1
0
 private ShoppingCartItem findItem(String itemId) {
   ShoppingCartItem item = null;
   int size = getSize();
   for (int i = 0; i < size; i++) {
     ShoppingCartItem cartItem = (ShoppingCartItem) items.get(i);
     if (itemId.equals(Integer.toString(cartItem.getItemId()))) {
       item = cartItem;
       break;
     }
   }
   return item;
 }
 @Override
 public void readData(ObjectDataInput in) throws IOException {
   total = in.readLong();
   date = new Date(in.readLong());
   id = in.readLong();
   int count = in.readInt();
   items = new ArrayList<>(count);
   for (int i = 0; i < count; i++) {
     ShoppingCartItem item = new ShoppingCartItem();
     item.readData(in);
     items.add(item);
   }
 }
Example #3
0
  public void addItem(ShoppingCartItem newItem) {

    // Check to see if this item is already present, if so, inc the qty
    int size = getSize();
    ShoppingCartItem cartItem = findItem(Integer.toString(newItem.getItemId()));
    if (cartItem != null) {
      cartItem.setQuantity(cartItem.getQuantity() + newItem.getQuantity());
    } else {

      // Must have been a different item, so add it to the cart
      items.add(newItem);
    }
  }
Example #4
0
 public void updateQuantity(String itemId, int newQty) {
   ShoppingCartItem item = findItem(itemId);
   if (item != null) {
     item.setQuantity(newQty);
   }
 }
  /*
   * Processes the customer order by forwarding the order details to the supplier.
   */
  public String submit() {
    ocs = new OrderConfirmations();

    FacesContext context = FacesContext.getCurrentInstance();
    ELContext elContext = context.getCurrentInstance().getELContext();
    ValueExpression ve =
        context
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(elContext, "#{CoffeeBreakBean}", Object.class);
    CoffeeBreakBean cbBean = (CoffeeBreakBean) ve.getValue(elContext);

    RetailPriceList rpl = cbBean.getRetailPriceList();
    ShoppingCart cart = cbBean.getCart();

    ConfirmationBean confirmation = null;
    String orderId = CCNumber;

    AddressBean address = new AddressBean();
    address.setStreet(street);
    address.setCity(city);
    address.setState(state);
    address.setZip(zip);

    CustomerBean customer = new CustomerBean();
    customer.setFirstName(firstName);
    customer.setLastName(lastName);
    customer.setPhoneNumber("(" + areaCode + ") " + phoneNumber);
    customer.setEmailAddress(email);

    for (Iterator d = rpl.getSuppliers().iterator(); d.hasNext(); ) {
      String supplier = (String) d.next();
      logger.info(supplier);

      List<LineItemBean> lis = new ArrayList<LineItemBean>();
      BigDecimal price = new BigDecimal("0.00");
      BigDecimal total = new BigDecimal("0.00");

      for (Iterator c = cart.getItems().iterator(); c.hasNext(); ) {
        ShoppingCartItem sci = (ShoppingCartItem) c.next();

        if ((sci.getItem().getSupplier()).equals(supplier)
            && ((sci.getPounds()).floatValue() > 0)) {
          price = sci.getItem().getWholesalePricePerPound().multiply(sci.getPounds());
          total = total.add(price);

          LineItemBean li = new LineItemBean();
          li.setCoffeeName(sci.getItem().getCoffeeName());
          li.setPounds(sci.getPounds());
          li.setPrice(sci.getItem().getWholesalePricePerPound());
          lis.add(li);
        }
      }

      if (!lis.isEmpty()) {
        logger.info("creating OrderBean");

        OrderBean order = new OrderBean();
        order.setAddress(address);
        order.setCustomer(customer);
        order.setId(orderId);

        int i = 0;

        for (Iterator<LineItemBean> j = lis.iterator(); j.hasNext(); ) {
          order.getLineItems().add(j.next());
          i++;
        }

        order.setTotal(total);

        String SAAJOrderURL = URLHelper.getSaajURL() + "/orderCoffee";

        if (supplier.equals(SAAJOrderURL)) {
          logger.info("creating OrderRequest for" + SAAJOrderURL);

          OrderRequest or = new OrderRequest(SAAJOrderURL);
          confirmation = or.placeOrder(order);
        } else {
          logger.info("creating OrderCaller");

          OrderCaller ocaller = new OrderCaller(supplier);
          confirmation = ocaller.placeOrder(order);
        }

        logger.info("crating OrderConfirmation");

        OrderConfirmation oc = new OrderConfirmation(order, confirmation);
        ocs.add(oc);
      }
    }

    logger.info("returning submit");

    return "submit";
  }
 /** Remove the item from the shopping cart. */
 public void removeItem(ShoppingCartItem si) {
   table.remove(si.getID());
 }
 /** Update the item in the shopping cart. */
 public void updateItem(ShoppingCartItem si) {
   table.put(si.getID(), new Integer(si.getQuantity()));
 }
Example #8
0
  public void sessionDestroyed(HttpSessionEvent event) {
    HttpSession session = event.getSession();
    ShoppingCart cart = (ShoppingCart) session.getAttribute("shoppingCart");
    if (cart == null) {
      Debug.logInfo("No cart to save, doing nothing.", module);
      return;
    }

    String delegatorName = (String) session.getAttribute("delegatorName");
    Delegator delegator = null;
    if (UtilValidate.isNotEmpty(delegatorName)) {
      delegator = DelegatorFactory.getDelegator(delegatorName);
    }
    if (delegator == null) {
      Debug.logError(
          "Could not find delegator with delegatorName in session, not saving abandoned cart info.",
          module);
      return;
    }

    boolean beganTransaction = false;
    try {
      beganTransaction = TransactionUtil.begin();

      GenericValue visit = VisitHandler.getVisit(session);
      if (visit == null) {
        Debug.logError("Could not get the current visit, not saving abandoned cart info.", module);
        return;
      }

      Debug.logInfo("Saving abandoned cart", module);
      Iterator cartItems = cart.iterator();
      int seqId = 1;
      while (cartItems.hasNext()) {
        ShoppingCartItem cartItem = (ShoppingCartItem) cartItems.next();
        GenericValue cartAbandonedLine = delegator.makeValue("CartAbandonedLine");

        cartAbandonedLine.set("visitId", visit.get("visitId"));
        cartAbandonedLine.set("cartAbandonedLineSeqId", (Integer.valueOf(seqId)).toString());
        cartAbandonedLine.set("productId", cartItem.getProductId());
        cartAbandonedLine.set("prodCatalogId", cartItem.getProdCatalogId());
        cartAbandonedLine.set("quantity", cartItem.getQuantity());
        cartAbandonedLine.set("reservStart", cartItem.getReservStart());
        cartAbandonedLine.set("reservLength", cartItem.getReservLength());
        cartAbandonedLine.set("reservPersons", cartItem.getReservPersons());
        cartAbandonedLine.set("unitPrice", cartItem.getBasePrice());
        cartAbandonedLine.set("reserv2ndPPPerc", cartItem.getReserv2ndPPPerc());
        cartAbandonedLine.set("reservNthPPPerc", cartItem.getReservNthPPPerc());
        if (cartItem.getConfigWrapper() != null) {
          cartAbandonedLine.set("configId", cartItem.getConfigWrapper().getConfigId());
        }
        cartAbandonedLine.set("totalWithAdjustments", cartItem.getItemSubTotal());
        // not doing pre-reservations now, so this is always N
        cartAbandonedLine.set("wasReserved", "N");
        cartAbandonedLine.create();

        seqId++;
      }
    } catch (GenericEntityException e) {
      try {
        // only rollback the transaction if we started one...
        TransactionUtil.rollback(beganTransaction, "Error saving abandoned cart info", e);
      } catch (GenericEntityException e2) {
        Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module);
      }

      Debug.logError(
          e, "An entity engine error occurred while saving abandoned cart information", module);
    } finally {
      // only commit the transaction if we started one... this will throw an exception if it fails
      try {
        TransactionUtil.commit(beganTransaction);
      } catch (GenericEntityException e) {
        Debug.logError(
            e,
            "Could not commit transaction for entity engine error occurred while saving abandoned cart information",
            module);
      }
    }
  }