Search in sources :

Example 11 with ShoppingCartItem

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();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) AjaxResponse(com.salesmanager.core.business.utils.ajax.AjaxResponse) ShoppingCartItem(com.salesmanager.shop.model.shoppingcart.ShoppingCartItem) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ShoppingCartData(com.salesmanager.shop.model.shoppingcart.ShoppingCartData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ShoppingCartItem (com.salesmanager.shop.model.shoppingcart.ShoppingCartItem)11 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)6 HashSet (java.util.HashSet)6 PersistableShoppingCartItem (com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem)5 ReadableShoppingCart (com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart)5 ArrayList (java.util.ArrayList)5 ServiceException (com.salesmanager.core.business.exception.ServiceException)4 Product (com.salesmanager.core.model.catalog.product.Product)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)4 ShoppingCartAttribute (com.salesmanager.shop.model.shoppingcart.ShoppingCartAttribute)4 ShoppingCartData (com.salesmanager.shop.model.shoppingcart.ShoppingCartData)4 ShoppingCartDataPopulator (com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator)4 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)3 Customer (com.salesmanager.core.model.customer.Customer)3 ConversionException (org.apache.commons.beanutils.ConversionException)3 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)2 PageInformation (com.salesmanager.shop.model.shop.PageInformation)2 CartModificationException (com.salesmanager.shop.model.shoppingcart.CartModificationException)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2