Search in sources :

Example 11 with ReadableShoppingCart

use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.

the class ShoppingCartApi method getByCustomer.

@Deprecated
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/{id}/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by customer id. Customer must be authenticated", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
// customer
@ResponseBody
public // customer
ReadableShoppingCart getByCustomer(// customer
@PathVariable Long id, // cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    Principal principal = request.getUserPrincipal();
    // lookup customer
    Customer customer = customerService.getById(id);
    if (customer == null) {
        throw new ResourceNotFoundException("No Customer found for id [" + id + "]");
    }
    customerFacadev1.authorize(customer, principal);
    ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, id, merchantStore, language);
    if (readableCart == null) {
        throw new ResourceNotFoundException("No cart found for customerid [" + id + "]");
    }
    return readableCart;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with ReadableShoppingCart

use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.

the class ShoppingCartApi method getByCustomer.

@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by authenticated customer", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableShoppingCart getByCustomer(// cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    Principal principal = request.getUserPrincipal();
    Customer customer = null;
    try {
        customer = customerFacade.getCustomerByUserName(principal.getName(), merchantStore);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while getting customer [ " + principal.getName() + "]");
    }
    if (customer == null) {
        throw new ResourceNotFoundException("No Customer found for principal[" + principal.getName() + "]");
    }
    customerFacadev1.authorize(customer, principal);
    ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, customer.getId(), merchantStore, language);
    if (readableCart == null) {
        throw new ResourceNotFoundException("No cart found for customer [" + principal.getName() + "]");
    }
    return readableCart;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with ReadableShoppingCart

use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.

the class ShoppingCartFacadeImpl method getCart.

@Override
public ReadableShoppingCart getCart(Customer customer, MerchantStore store, Language language) throws Exception {
    Validate.notNull(customer, "Customer cannot be null");
    Validate.notNull(customer.getId(), "Customer.id cannot be null or empty");
    // Check if customer has an existing shopping cart
    ShoppingCart cartModel = shoppingCartService.getShoppingCart(customer);
    if (cartModel == null) {
        return null;
    }
    shoppingCartCalculationService.calculate(cartModel, store, language);
    ReadableShoppingCart readableCart = new ReadableShoppingCart();
    readableCart = readableShoppingCartMapper.convert(cartModel, store, language);
    return readableCart;
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart)

Example 14 with ReadableShoppingCart

use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.

the class ShoppingCartFacadeImpl method modifyCartMulti.

@Override
public ReadableShoppingCart modifyCartMulti(String cartCode, List<PersistableShoppingCartItem> items, MerchantStore store, Language language) throws Exception {
    Validate.notNull(cartCode, "String cart code cannot be null");
    Validate.notNull(items, "PersistableShoppingCartItem cannot be null");
    ShoppingCart cartModel = this.getCartModel(cartCode, store);
    if (cartModel == null) {
        throw new IllegalArgumentException("Cart code not valid");
    }
    return modifyCartMulti(cartModel, items, store, language);
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart)

Example 15 with ReadableShoppingCart

use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.

the class ShoppingCartFacadeImpl method modifyCart.

@Override
public ReadableShoppingCart modifyCart(String cartCode, PersistableShoppingCartItem item, MerchantStore store, Language language) throws Exception {
    Validate.notNull(cartCode, "String cart code cannot be null");
    Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
    ShoppingCart cartModel = getCartModel(cartCode, store);
    if (cartModel == null) {
        throw new ResourceNotFoundException("Cart code [" + cartCode + "] not found");
    }
    return modifyCart(cartModel, item, store, language);
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

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