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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations