Search in sources :

Example 16 with ReadableShoppingCart

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);
    }
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 17 with ReadableShoppingCart

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);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with ReadableShoppingCart

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());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with ReadableShoppingCart

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));
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ReadableShoppingCart (com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart)19 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)10 PersistableShoppingCartItem (com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem)8 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)6 HttpEntity (org.springframework.http.HttpEntity)6 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)4 LocalDate (java.time.LocalDate)4 Date (java.util.Date)4 Customer (com.salesmanager.core.model.customer.Customer)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ShoppingCartItem (com.salesmanager.shop.model.shoppingcart.ShoppingCartItem)2 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2