Search in sources :

Example 6 with ReviewDetail

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;
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 7 with ReviewDetail

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();
}
Also used : ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 8 with ReviewDetail

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);
    }
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray)

Aggregations

ReviewDetail (org.broadleafcommerce.core.rating.domain.ReviewDetail)8 RatingSummary (org.broadleafcommerce.core.rating.domain.RatingSummary)4 NoResultException (javax.persistence.NoResultException)2 Query (javax.persistence.Query)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 RatingDetail (org.broadleafcommerce.core.rating.domain.RatingDetail)1 ReviewDetailImpl (org.broadleafcommerce.core.rating.domain.ReviewDetailImpl)1 ReviewFeedback (org.broadleafcommerce.core.rating.domain.ReviewFeedback)1 Customer (org.broadleafcommerce.profile.core.domain.Customer)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONObject (org.codehaus.jettison.json.JSONObject)1