Search in sources :

Example 6 with RatingSummary

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

Example 7 with RatingSummary

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;
}
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 8 with RatingSummary

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);
    }
}
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)

Example 9 with RatingSummary

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

Example 10 with RatingSummary

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);
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) RatingDetail(org.broadleafcommerce.core.rating.domain.RatingDetail) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

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