Package org.springframework.samples.jpetstore.domain

Examples of org.springframework.samples.jpetstore.domain.Cart


* @since 30.11.2003
*/
public class RemoveItemFromCartController implements Controller {

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class);
    cart.removeItemById(request.getParameter("workingItemId"));
    return new ModelAndView("Cart", "cart", cart);
  }
View Full Code Here


    this.petStore = petStore;
  }

  protected Object formBackingObject(HttpServletRequest request) throws ModelAndViewDefiningException {
    UserSession userSession = (UserSession) request.getSession().getAttribute("userSession");
    Cart cart = (Cart) request.getSession().getAttribute("sessionCart");
    if (cart != null) {
      // Re-read account from DB at team's request.
      Account account = this.petStore.getAccount(userSession.getAccount().getUsername());
      OrderForm orderForm = new OrderForm();
      orderForm.getOrder().initOrder(account, cart);
View Full Code Here

* @since 30.11.2003
*/
public class UpdateCartQuantitiesController implements Controller {

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class);
    Iterator cartItems = cart.getAllCartItems();
    while (cartItems.hasNext()) {
      CartItem cartItem = (CartItem) cartItems.next();
      String itemId = cartItem.getItem().getItemId();
      try {
        int quantity = Integer.parseInt(request.getParameter(itemId));
        cart.setQuantityByItemId(itemId, quantity);
        if (quantity < 1) {
          cartItems.remove();
        }
      }
      catch (NumberFormatException ex) {
View Full Code Here

    this.successView = successView;
  }

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession");
    Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class);
    String page = request.getParameter("page");
    if (userSession != null) {
      if ("next".equals(page)) {
        userSession.getMyList().nextPage();
      }
      else if ("previous".equals(page)) {
        userSession.getMyList().previousPage();
      }
    }
    if ("nextCart".equals(page)) {
      cart.getCartItemList().nextPage();
    }
    else if ("previousCart".equals(page)) {
      cart.getCartItemList().previousPage();
    }
    return new ModelAndView(this.successView, "cart", cart);
  }
View Full Code Here

  public void setPetStore(PetStoreFacade petStore) {
    this.petStore = petStore;
  }

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class);
    String workingItemId = request.getParameter("workingItemId");
    if (cart.containsItemId(workingItemId)) {
      cart.incrementQuantityByItemId(workingItemId);
    }
    else {
      // isInStock is a "real-time" property that must be updated
      // every time an item is added to the cart, even if other
      // item details are cached.
      boolean isInStock = this.petStore.isItemInStock(workingItemId);
      Item item = this.petStore.getItem(workingItemId);
      cart.addItem(item, isInStock);
    }
    return new ModelAndView("Cart", "cart", cart);
  }
View Full Code Here

public class AddItemToCartAction extends BaseAction {

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    CartActionForm cartForm = (CartActionForm) form;
    Cart cart = cartForm.getCart();
    String workingItemId = cartForm.getWorkingItemId();
    if (cart.containsItemId(workingItemId)) {
      cart.incrementQuantityByItemId(workingItemId);
    }
    else {
      // isInStock is a "real-time" property that must be updated
      // every time an item is added to the cart, even if other
      // item details are cached.
View Full Code Here

TOP

Related Classes of org.springframework.samples.jpetstore.domain.Cart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.