use of com.salesmanager.shop.model.shoppingcart.ShoppingCartItem in project shopizer by shopizer-ecommerce.
the class ShoppingCartController method updateShoppingCartItem.
/**
* Update the quantity of an item in the Shopping Cart (AJAX exposed method)
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/updateShoppingCartItem.html" }, method = { RequestMethod.POST })
@ResponseBody
public String updateShoppingCartItem(@RequestBody final ShoppingCartItem[] shoppingCartItems, final HttpServletRequest request, final HttpServletResponse response) {
AjaxResponse ajaxResponse = new AjaxResponse();
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
String cartCode = (String) request.getSession().getAttribute(Constants.SHOPPING_CART);
if (StringUtils.isBlank(cartCode)) {
return "redirect:/shop";
}
/**
* if a promo code is captured *
*/
String pCode = request.getParameter("promoCode");
Optional<String> promoCode = Optional.ofNullable(pCode);
try {
List<ShoppingCartItem> items = Arrays.asList(shoppingCartItems);
ShoppingCartData shoppingCart = shoppingCartFacade.updateCartItems(promoCode, items, store, language);
ajaxResponse.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
} catch (Exception e) {
LOG.error("Excption while updating cart", e);
ajaxResponse.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
}
return ajaxResponse.toJSONString();
}
Aggregations