@RequestMapping(
      value = "/cart/update",
      method = RequestMethod.POST,
      produces = "application/json")
  public String updateCartQuantities(
      @RequestParam("storeNamePost") final String storeId,
      @RequestParam("entryNumber") final long entryNumber,
      @RequestParam("hiddenPickupQty") final long quantity,
      final RedirectAttributes redirectModel)
      throws CommerceCartModificationException {
    final CartModificationData cartModificationData =
        cartFacade.updateCartEntry(entryNumber, storeId);

    if (entryNumber == cartModificationData.getEntry().getEntryNumber().intValue()) {
      final CartModificationData cartModification =
          cartFacade.updateCartEntry(entryNumber, quantity);
      if (cartModification.getQuantity() == quantity) {
        // Success
        if (cartModification.getQuantity() == 0) {
          // Success in removing entry
          GlobalMessages.addFlashMessage(
              redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "basket.page.message.remove");
        } else {
          // Success in update quantity
          GlobalMessages.addFlashMessage(
              redirectModel,
              GlobalMessages.CONF_MESSAGES_HOLDER,
              "basket.page.message.update.pickupinstoreitem");
        }
      } else {
        // Less than successful
        GlobalMessages.addFlashMessage(
            redirectModel,
            GlobalMessages.ERROR_MESSAGES_HOLDER,
            "basket.information.quantity.reducedNumberOfItemsAdded."
                + cartModification.getStatusCode());
      }
    } else if (!CommerceCartModificationStatus.SUCCESS.equals(
        cartModificationData.getStatusCode())) {
      // When update pickupInStore happens to be same as existing entry with POS and SKU and that
      // merged POS has lower stock
      GlobalMessages.addFlashMessage(
          redirectModel,
          GlobalMessages.ERROR_MESSAGES_HOLDER,
          "basket.information.quantity.reducedNumberOfItemsAdded."
              + cartModificationData.getStatusCode());
    }

    return REDIRECT_PREFIX + "/cart";
  }
 @RequestMapping(
     value = "/summary/reorder",
     method = {RequestMethod.PUT, RequestMethod.POST})
 @RequireHardLogIn
 public String reorder(
     @RequestParam(value = "orderCode") final String orderCode,
     final RedirectAttributes redirectModel)
     throws CMSItemNotFoundException, InvalidCartException, ParseException,
         CommerceCartModificationException {
   // create a cart from the order and set it as session cart.
   getB2BCheckoutFacade().createCartFromOrder(orderCode);
   // validate for stock and availability
   final List<CartModificationData> cartModifications = doNotUsecartFacade.validateCartData();
   for (final CartModificationData cartModification : cartModifications) {
     if (CommerceCartModificationStatus.NO_STOCK.equals(cartModification.getStatusCode())) {
       GlobalMessages.addFlashMessage(
           redirectModel,
           GlobalMessages.ERROR_MESSAGES_HOLDER,
           "basket.page.message.update.reducedNumberOfItemsAdded.noStock",
           new Object[] {cartModification.getEntry().getProduct().getName()});
       break;
     } else if (cartModification.getQuantity() != cartModification.getQuantityAdded()) {
       // item has been modified to match available stock levels
       GlobalMessages.addFlashMessage(
           redirectModel,
           GlobalMessages.ERROR_MESSAGES_HOLDER,
           "basket.information.quantity.adjusted");
       break;
     }
     // TODO: handle more specific messaging, i.e. out of stock, product not available
   }
   return REDIRECT_PREFIX + "/checkout/single/summary"; // checkoutSummary(model);
 }
 @Test
 public void testAddToCart() {
   final CartModificationData modification = classUnderTest.addToCart(productId, quantity);
   assertNotNull(modification);
   assertTrue(modification.getQuantity() == quantity);
   assertTrue(modification.getQuantityAdded() == quantity);
 }