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);
}