use of org.broadleafcommerce.core.rating.domain.ReviewDetail in project BroadleafCommerce by BroadleafCommerce.
the class RatingsProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
String itemId = String.valueOf(context.parseExpression(tagAttributes.get("itemId")));
RatingSummary ratingSummary = ratingService.readRatingSummary(itemId, RatingType.PRODUCT);
Map<String, Object> newModelVars = new HashMap<>();
if (ratingSummary != null) {
newModelVars.put(getRatingsVar(tagAttributes), ratingSummary);
}
Customer customer = CustomerState.getCustomer();
ReviewDetail reviewDetail = null;
if (!customer.isAnonymous()) {
reviewDetail = ratingService.readReviewByCustomerAndItem(customer, itemId);
}
if (reviewDetail != null) {
newModelVars.put("currentCustomerReview", reviewDetail);
}
return newModelVars;
}
use of org.broadleafcommerce.core.rating.domain.ReviewDetail in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafRatingsController method viewReviewForm.
public String viewReviewForm(HttpServletRequest request, Model model, ReviewForm form, String itemId) {
Product product = catalogService.findProductById(Long.valueOf(itemId));
form.setProduct(product);
ReviewDetail reviewDetail = ratingService.readReviewByCustomerAndItem(CustomerState.getCustomer(), itemId);
if (reviewDetail != null) {
form.setReviewText(reviewDetail.getReviewText());
form.setRating(reviewDetail.getRatingDetail().getRating());
}
model.addAttribute("reviewForm", form);
return getFormView();
}
use of org.broadleafcommerce.core.rating.domain.ReviewDetail in project BroadleafCommerce by BroadleafCommerce.
the class ProductLinkedDataGeneratorImpl method addReviewData.
protected void addReviewData(final HttpServletRequest request, final Product product, final JSONObject productData) throws JSONException {
final RatingSummary ratingSummary = ratingService.readRatingSummary(product.getId().toString(), RatingType.PRODUCT);
if (ratingSummary != null && ratingSummary.getNumberOfRatings() > 0) {
final JSONObject aggregateRating = new JSONObject();
aggregateRating.put("ratingCount", ratingSummary.getNumberOfRatings());
aggregateRating.put("ratingValue", ratingSummary.getAverageRating());
extensionManager.getProxy().addAggregateReviewData(request, product, aggregateRating);
productData.put("aggregateRating", aggregateRating);
final JSONArray reviews = new JSONArray();
for (final ReviewDetail reviewDetail : ratingSummary.getReviews()) {
final JSONObject review = new JSONObject();
review.put("reviewBody", reviewDetail.getReviewText());
review.put("reviewRating", new JSONObject().put("ratingValue", reviewDetail.getRatingDetail().getRating()));
review.put("author", reviewDetail.getCustomer().getFirstName());
review.put("datePublished", ISO_8601_FORMAT.format(reviewDetail.getReviewSubmittedDate()));
extensionManager.getProxy().addReviewData(request, product, review);
reviews.put(review);
}
productData.put("review", reviews);
}
}
Aggregations