use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProductReviews.
@Override
public List<ReadableProductReview> getProductReviews(Product product, MerchantStore store, Language language) throws Exception {
List<ProductReview> reviews = productReviewService.getByProduct(product);
ReadableProductReviewPopulator populator = new ReadableProductReviewPopulator();
List<ReadableProductReview> productReviews = new ArrayList<ReadableProductReview>();
for (ProductReview review : reviews) {
ReadableProductReview readableReview = new ReadableProductReview();
populator.populate(review, readableReview, store, language);
productReviews.add(readableReview);
}
return productReviews;
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class CustomerProductReviewController method displayProductReview.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/review.html", method = RequestMethod.GET)
public String displayProductReview(@RequestParam Long productId, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = super.getLanguage(request);
// get product
Product product = productService.getById(productId);
if (product == null) {
return "redirect:" + Constants.SHOP_URI;
}
if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
return "redirect:" + Constants.SHOP_URI;
}
// create readable product
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator readableProductPopulator = new ReadableProductPopulator();
readableProductPopulator.setPricingService(pricingService);
readableProductPopulator.setimageUtils(imageUtils);
readableProductPopulator.populate(product, readableProduct, store, language);
model.addAttribute("product", readableProduct);
Customer customer = customerFacade.getCustomerByUserName(request.getRemoteUser(), store);
List<ProductReview> reviews = productReviewService.getByProduct(product, language);
for (ProductReview r : reviews) {
if (r.getCustomer().getId().longValue() == customer.getId().longValue()) {
ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
ReadableProductReview rev = new ReadableProductReview();
reviewPopulator.populate(r, rev, store, language);
model.addAttribute("customerReview", rev);
break;
}
}
ProductReview review = new ProductReview();
review.setCustomer(customer);
review.setProduct(product);
ReadableProductReview productReview = new ReadableProductReview();
ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
reviewPopulator.populate(review, productReview, store, language);
model.addAttribute("review", productReview);
model.addAttribute("reviews", reviews);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.review).append(".").append(store.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProductReviews.
@Override
public List<ReadableProductReview> getProductReviews(Product product, MerchantStore store, Language language) throws Exception {
List<ProductReview> reviews = productReviewService.getByProduct(product);
ReadableProductReviewPopulator populator = new ReadableProductReviewPopulator();
List<ReadableProductReview> productReviews = new ArrayList<ReadableProductReview>();
for (ProductReview review : reviews) {
ReadableProductReview readableReview = new ReadableProductReview();
populator.populate(review, readableReview, store, language);
productReviews.add(readableReview);
}
return productReviews;
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class PersistableProductReviewPopulator method populate.
@Override
public ProductReview populate(PersistableProductReview source, ProductReview target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(customerService, "customerService cannot be null");
Validate.notNull(productService, "productService cannot be null");
Validate.notNull(languageService, "languageService cannot be null");
Validate.notNull(source.getRating(), "Rating cannot bot be null");
try {
if (target == null) {
target = new ProductReview();
}
Customer customer = customerService.getById(source.getCustomerId());
// check if customer belongs to store
if (customer == null || customer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer id for the given store");
}
if (source.getDate() == null) {
String date = DateUtil.formatDate(new Date());
source.setDate(date);
}
target.setReviewDate(DateUtil.getDate(source.getDate()));
target.setCustomer(customer);
target.setReviewRating(source.getRating());
Product product = productService.getById(source.getProductId());
// check if product belongs to store
if (product == null || product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid product id for the given store");
}
target.setProduct(product);
Language lang = languageService.getByCode(language.getCode());
if (lang == null) {
throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
}
ProductReviewDescription description = new ProductReviewDescription();
description.setDescription(source.getDescription());
description.setLanguage(lang);
description.setName("-");
description.setProductReview(target);
Set<ProductReviewDescription> descriptions = new HashSet<ProductReviewDescription>();
descriptions.add(description);
target.setDescriptions(descriptions);
return target;
} catch (Exception e) {
throw new ConversionException("Cannot populate ProductReview", e);
}
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ProductReviewApi method delete.
@RequestMapping(value = { "/private/products/{id}/reviews/{reviewid}", "/auth/products/{id}/reviews/{reviewid}" }, method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void delete(@PathVariable final Long id, @PathVariable final Long reviewId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
try {
ProductReview prodReview = productReviewService.getById(reviewId);
if (prodReview == null) {
response.sendError(404, "Product review with id " + reviewId + " does not exist");
return;
}
if (prodReview.getProduct().getId().longValue() != id.longValue()) {
response.sendError(404, "Product review with id " + reviewId + " does not exist");
return;
}
productCommonFacade.deleteReview(prodReview, merchantStore, language);
} catch (Exception e) {
LOGGER.error("Error while deleting product review", e);
try {
response.sendError(503, "Error while deleting product review" + e.getMessage());
} catch (Exception ignore) {
}
return;
}
}
Aggregations