use of com.salesmanager.shop.model.catalog.product.ReadableProduct 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;
}
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProduct.
@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) {
Product product = productService.findOne(id, store);
if (product == null) {
throw new ResourceNotFoundException("Product [" + id + "] not found");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
}
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
try {
readableProduct = populator.populate(product, readableProduct, store, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Error converting product [" + id + "]", e);
}
return readableProduct;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method updateProductPrice.
@Override
public ReadableProduct updateProductPrice(ReadableProduct product, ProductPriceEntity price, Language language) throws Exception {
Product persistable = productService.getById(product.getId());
if (persistable == null) {
throw new Exception("product is null for id " + product.getId());
}
java.util.Set<ProductAvailability> availabilities = persistable.getAvailabilities();
for (ProductAvailability availability : availabilities) {
ProductPrice productPrice = availability.defaultPrice();
productPrice.setProductPriceAmount(price.getOriginalPrice());
if (price.isDiscounted()) {
productPrice.setProductPriceSpecialAmount(price.getDiscountedPrice());
if (!StringUtils.isBlank(price.getDiscountStartDate())) {
Date startDate = DateUtil.getDate(price.getDiscountStartDate());
productPrice.setProductPriceSpecialStartDate(startDate);
}
if (!StringUtils.isBlank(price.getDiscountEndDate())) {
Date endDate = DateUtil.getDate(price.getDiscountEndDate());
productPrice.setProductPriceSpecialEndDate(endDate);
}
}
}
productService.update(persistable);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(persistable, readableProduct, persistable.getMerchantStore(), language);
return readableProduct;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method removeProductFromCategory.
@Override
public ReadableProduct removeProductFromCategory(Category category, Product product, Language language) throws Exception {
Validate.notNull(category, "Category cannot be null");
Validate.notNull(product, "Product cannot be null");
product.getCategories().remove(category);
productService.update(product);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(product, readableProduct, product.getMerchantStore(), language);
return readableProduct;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProductByCode.
@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) throws Exception {
Product product = productService.getByCode(uniqueCode, language);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(product, readableProduct, product.getMerchantStore(), language);
return readableProduct;
}
Aggregations