use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method get.
// facade
@Override
public ReadableShoppingCart get(Optional<String> cart, Long customerId, MerchantStore store, Language language) {
Validate.notNull(customerId, "Customer id cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
try {
// lookup customer
Customer customer = customerService.getById(customerId);
if (customer == null) {
throw new ResourceNotFoundException("No Customer found for id [" + customerId + "]");
}
ShoppingCart cartModel = shoppingCartService.getShoppingCart(customer);
if (cart.isPresent()) {
cartModel = customerFacade.mergeCart(customer, cart.get(), store, language);
}
if (cartModel == null) {
return null;
}
ReadableShoppingCart readableCart = shoppingCartFacade.readableCart(cartModel, store, language);
return readableCart;
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartAPIIntegrationTest method addSecondToCart.
/**
* Add an second Item to existing Cart, should give HTTP 201 & 2 qty
*
* @throws Exception
*/
@Test
@Order(2)
public void addSecondToCart() throws Exception {
ReadableProduct product = sampleProduct("add2Cart");
assertNotNull(product);
data.getProducts().add(product);
PersistableShoppingCartItem cartItem = new PersistableShoppingCartItem();
cartItem.setProduct(product.getId());
cartItem.setQuantity(1);
final HttpEntity<PersistableShoppingCartItem> cartEntity = new HttpEntity<>(cartItem, getHeader());
final ResponseEntity<ReadableShoppingCart> response = testRestTemplate.exchange(String.format("/api/v1/cart/" + String.valueOf(data.getCartId())), HttpMethod.PUT, cartEntity, ReadableShoppingCart.class);
assertNotNull(response);
assertThat(response.getStatusCode(), is(CREATED));
assertEquals(response.getBody().getQuantity(), 2);
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartAPIIntegrationTest method updateMultiWZeroOnOneProd.
/**
* Update cart with qnt 0 on one cart item which gives 3 qty left
*
* @throws Exception
*/
@Test
@Order(5)
public void updateMultiWZeroOnOneProd() throws Exception {
PersistableShoppingCartItem cartItem1 = new PersistableShoppingCartItem();
cartItem1.setProduct(data.getProducts().get(0).getId());
cartItem1.setQuantity(0);
PersistableShoppingCartItem[] productsQtyUpdates = { cartItem1 };
final HttpEntity<PersistableShoppingCartItem[]> cartEntity = new HttpEntity<>(productsQtyUpdates, getHeader());
final ResponseEntity<ReadableShoppingCart> response = testRestTemplate.exchange(String.format("/api/v1/cart/" + data.getCartId() + "/multi"), HttpMethod.POST, cartEntity, ReadableShoppingCart.class);
assertNotNull(response);
assertThat(response.getStatusCode(), is(CREATED));
assertEquals(3, response.getBody().getQuantity());
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartAPIIntegrationTest method addToWrongToCartId.
/**
* Add an other item to cart which then does not exist which should return HTTP 404
*
* @throws Exception
*/
@Test
@Order(3)
public void addToWrongToCartId() throws Exception {
ReadableProduct product = sampleProduct("add3Cart");
assertNotNull(product);
data.getProducts().add(product);
PersistableShoppingCartItem cartItem = new PersistableShoppingCartItem();
cartItem.setProduct(product.getId());
cartItem.setQuantity(1);
final HttpEntity<PersistableShoppingCartItem> cartEntity = new HttpEntity<>(cartItem, getHeader());
final ResponseEntity<ReadableShoppingCart> response = testRestTemplate.exchange(String.format("/api/v1/cart/" + data.getCartId() + "breakIt"), HttpMethod.PUT, cartEntity, ReadableShoppingCart.class);
assertNotNull(response);
assertThat(response.getStatusCode(), is(NOT_FOUND));
}
Aggregations