use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingSummaryDaoImpl method createSummary.
@Override
public RatingSummary createSummary(String itemId, RatingType type) {
RatingSummary summary = createSummary();
summary.setItemId(itemId);
summary.setRatingType(type);
return summary;
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary 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.RatingSummary 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);
}
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingSummaryDaoImpl method deleteRatingSummary.
@Override
public void deleteRatingSummary(final RatingSummary summary) {
RatingSummary lSummary = summary;
if (!em.contains(lSummary)) {
lSummary = em.find(RatingSummaryImpl.class, lSummary.getId());
}
em.remove(lSummary);
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingServiceImpl method rateItem.
@Override
@Transactional("blTransactionManager")
public void rateItem(String itemId, RatingType type, Customer customer, Double rating) {
RatingSummary ratingSummary = this.readRatingSummary(itemId, type);
if (ratingSummary == null) {
ratingSummary = ratingSummaryDao.createSummary(itemId, type);
}
RatingDetail ratingDetail = ratingSummaryDao.readRating(customer.getId(), ratingSummary.getId());
if (ratingDetail == null) {
ratingDetail = ratingSummaryDao.createDetail(ratingSummary, rating, SystemTime.asDate(), customer);
}
ratingDetail.setRating(rating);
ratingSummary.getRatings().add(ratingDetail);
ratingSummaryDao.saveRatingSummary(ratingSummary);
}
Aggregations