Package com.alibaba.sample.petstore.dal.dataobject

Examples of com.alibaba.sample.petstore.dal.dataobject.Cart


        assertEquals("FISH", cat.getCategoryId());
    }

    @Test
    public void getCartItems() {
        Cart cart = new Cart();

        cart.setQuantity("EST-1", 10);
        cart.setQuantity("EST-2", 100);

        storeManager.getCartItems(cart);

        assertProductItem(cart, 0, "EST-1", 10);
        assertProductItem(cart, 1, "EST-2", 100);

        assertEquals(165 + 1650, cart.getTotal().intValue());
    }
View Full Code Here


public class ViewCart {
    @Autowired
    private StoreManager storeManager;

    public void execute(HttpSession session, Context context) throws Exception {
        Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY);

        if (cart == null) {
            cart = new Cart();
        }

        cart = storeManager.getCartItems(cart);

        context.put("cart", cart);
View Full Code Here

public class CartAction {
    @Autowired
    private StoreManager storeManager;

    public void doAddItem(HttpSession session, @Param("itemId") String itemId, Context context) throws Exception {
        Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY);

        if (cart == null) {
            cart = new Cart();
        }

        cart.addCartItem(itemId);

        session.setAttribute(PETSTORE_CART_KEY, cart);

        context.put("itemAdded", Boolean.TRUE);
    }
View Full Code Here

        context.put("itemAdded", Boolean.TRUE);
    }

    public void doRemoveItem(HttpSession session, @Param("itemId") String itemId, Context context)
            throws WebxException {
        Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY);

        if (cart == null) {
            cart = new Cart();
        }

        cart.removeCartItem(itemId);

        session.setAttribute(PETSTORE_CART_KEY, cart);
    }
View Full Code Here

        session.setAttribute(PETSTORE_CART_KEY, cart);
    }

    public void doUpdate(HttpSession session, @FormGroups("cartItem") Group[] groups, Context context)
            throws WebxException {
        Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY);

        if (cart == null) {
            return;
        }

        cart = storeManager.getCartItems(cart);

        for (Group group : groups) {
            String itemId = group.getInstanceKey();
            int quantity = group.getField("quantity").getIntegerValue();
            int stockQuantity = cart.getCartItem(itemId).getProductItem().getQuantity();

            if (quantity > stockQuantity) {
                Map<String, Object> params = createHashMap();
                params.put("stockQuantity", new Integer(stockQuantity));

                group.getField("quantity").setMessage("outOfStock", params);
            } else {
                cart.setQuantity(itemId, quantity);
            }
        }

        session.setAttribute(PETSTORE_CART_KEY, cart);
    }
View Full Code Here

TOP

Related Classes of com.alibaba.sample.petstore.dal.dataobject.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.