use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductGroupApi method addProductToGroup.
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/private/products/{productId}/group/{code}", method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableProductList addProductToGroup(@PathVariable Long productId, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
Product product = null;
try {
// get the product
product = productService.getById(productId);
if (product == null) {
response.sendError(404, "Product not fount for id " + productId);
return null;
}
} catch (Exception e) {
LOGGER.error("Error while adding product to group", e);
try {
response.sendError(503, "Error while adding product to group " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
ReadableProductList list = productItemsFacade.addItemToGroup(product, code, merchantStore, language);
return list;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductGroupApi method removeProductFromGroup.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/private/products/{productId}/group/{code}", method = RequestMethod.DELETE)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableProductList removeProductFromGroup(@PathVariable Long productId, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
// get the product
Product product = productService.getById(productId);
if (product == null) {
response.sendError(404, "Product not fount for id " + productId);
return null;
}
ReadableProductList list = productItemsFacade.removeItemFromGroup(product, code, merchantStore, language);
return list;
} catch (Exception e) {
LOGGER.error("Error while removing product from category", e);
try {
response.sendError(503, "Error while removing product from category " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductImageApi method uploadImage.
/**
* To be used with MultipartFile
*
* @param id
* @param uploadfiles
* @param request
* @param response
* @throws Exception
*/
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = { "/private/products/{id}/images", "/auth/products/{id}/images" }, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void uploadImage(@PathVariable Long id, @RequestParam(value = "file", required = true) MultipartFile[] files, @RequestParam(value = "order", required = false, defaultValue = "0") Integer position, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws IOException {
try {
// get the product
Product product = productService.getById(id);
if (product == null) {
throw new ResourceNotFoundException("Product not found");
}
// product belongs to merchant store
if (product.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
throw new UnauthorizedException("Resource not authorized for this merchant");
}
boolean hasDefaultImage = false;
Set<ProductImage> images = product.getImages();
if (!CollectionUtils.isEmpty(images)) {
for (ProductImage image : images) {
if (image.isDefaultImage()) {
hasDefaultImage = true;
break;
}
}
}
List<ProductImage> contentImagesList = new ArrayList<ProductImage>();
int sortOrder = position;
for (MultipartFile multipartFile : files) {
if (!multipartFile.isEmpty()) {
ProductImage productImage = new ProductImage();
productImage.setImage(multipartFile.getInputStream());
productImage.setProductImage(multipartFile.getOriginalFilename());
productImage.setProduct(product);
if (!hasDefaultImage) {
productImage.setDefaultImage(true);
hasDefaultImage = true;
}
productImage.setSortOrder(sortOrder);
position++;
contentImagesList.add(productImage);
}
}
if (CollectionUtils.isNotEmpty(contentImagesList)) {
productImageService.addProductImages(product, contentImagesList);
}
} catch (Exception e) {
LOGGER.error("Error while creating ProductImage", e);
throw new ServiceRuntimeException("Error while creating image");
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductImageApi method images.
/**
* Get product images
* @param id
* @param imageId
* @param merchantStore
* @param language
* @return
*/
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/products/{productId}/images" }, method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get images for a given product")
@ApiResponses(value = { @ApiResponse(code = 200, message = "List of ProductImage found", response = List.class) })
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ReadableImage> images(@PathVariable Long productId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
Product p = productService.getById(productId);
if (p == null) {
throw new ResourceNotFoundException("Product images not found for product id [" + productId + "] and merchant [" + merchantStore.getCode() + "]");
}
if (p.getMerchantStore().getId() != merchantStore.getId()) {
throw new ResourceNotFoundException("Product images not found for product id [" + productId + "] and merchant [" + merchantStore.getCode() + "]");
}
List<ReadableImage> target = new ArrayList<ReadableImage>();
Set<ProductImage> images = p.getImages();
if (images != null && images.size() > 0) {
target = images.stream().map(i -> image(i, merchantStore, language)).sorted(Comparator.comparingInt(ReadableImage::getOrder)).collect(Collectors.toList());
}
return target;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductRelationshipApi method getAll.
/* @RequestMapping( value={"/private/products/{id}/related","/auth/products/{id}/related"}, method=RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableProductReview create(@PathVariable final Long id, @Valid @RequestBody PersistableProductReview review, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
MerchantStore merchantStore = storeFacade.getByCode(request);
Language language = languageUtils.getRESTLanguage(request, merchantStore);
//rating already exist
ProductReview prodReview = productReviewService.getByProductAndCustomer(review.getProductId(), review.getCustomerId());
if(prodReview!=null) {
response.sendError(500, "A review already exist for this customer and product");
return null;
}
//rating maximum 5
if(review.getRating()>Constants.MAX_REVIEW_RATING_SCORE) {
response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
return null;
}
review.setProductId(id);
productFacade.saveOrUpdateReview(review, merchantStore, language);
return review;
} catch (Exception e) {
LOGGER.error("Error while saving product review",e);
try {
response.sendError(503, "Error while saving product review" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}*/
@RequestMapping(value = "/products/{id}/related", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(httpMethod = "GET", value = "Get product related items. This is used for doing cross-sell and up-sell functionality on a product details page", notes = "", produces = "application/json", response = List.class)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ReadableProduct> getAll(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception {
try {
// product exist
Product product = productService.getById(id);
if (product == null) {
response.sendError(404, "Product id " + id + " does not exists");
return null;
}
List<ReadableProduct> relatedItems = productFacade.relatedItems(merchantStore, product, language);
return relatedItems;
} catch (Exception e) {
LOGGER.error("Error while getting product reviews", e);
try {
response.sendError(503, "Error while getting product reviews" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations