public ProductOverviewModel()
 {
     ProductPrice                 = new ProductPriceModel();
     DefaultPictureModel          = new PictureModel();
     SpecificationAttributeModels = new List <ProductSpecificationModel>();
     ReviewOverviewModel          = new ProductReviewOverviewModel();
 }
        public ActionResult ReviewSummary(int id /* productId */)
        {
            var product = _productService.GetProductById(id);

            if (product == null)
            {
                throw new ArgumentException(T("Products.NotFound", id));
            }

            var model = new ProductReviewOverviewModel
            {
                ProductId            = product.Id,
                RatingSum            = product.ApprovedRatingSum,
                TotalReviews         = product.ApprovedTotalReviews,
                AllowCustomerReviews = product.AllowCustomerReviews
            };

            return(PartialView("Product.ReviewSummary", model));
        }
        public ActionResult ReviewOverview(int id)
        {
            var product = _productService.GetProductById(id);

            if (product == null)
            {
                throw new ArgumentException("No product found with the specified id");
            }

            var model = new ProductReviewOverviewModel()
            {
                ProductId            = product.Id,
                RatingSum            = product.ApprovedRatingSum,
                TotalReviews         = product.ApprovedTotalReviews,
                AllowCustomerReviews = product.AllowCustomerReviews
            };

            return(PartialView(model));
        }
Exemple #4
0
        public static ProductReviewOverviewModel PrepareProductReviewOverviewModel(this Controller controller,
                                                                                   IStoreContext storeContext,
                                                                                   CatalogSettings catalogSettings,
                                                                                   ICacheManager cacheManager,
                                                                                   Product product)
        {
            ProductReviewOverviewModel productReview;

            if (catalogSettings.ShowProductReviewsPerStore)
            {
                string cacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_REVIEWS_MODEL_KEY, product.Id, storeContext.CurrentStore.Id);

                productReview = cacheManager.Get(cacheKey, () =>
                {
                    return(new ProductReviewOverviewModel
                    {
                        RatingSum = product.ProductReviews
                                    .Where(pr => pr.IsApproved && pr.StoreId == storeContext.CurrentStore.Id)
                                    .Sum(pr => pr.Rating),
                        TotalReviews = product
                                       .ProductReviews
                                       .Count(pr => pr.IsApproved && pr.StoreId == storeContext.CurrentStore.Id)
                    });
                });
            }
            else
            {
                productReview = new ProductReviewOverviewModel()
                {
                    RatingSum    = product.ApprovedRatingSum,
                    TotalReviews = product.ApprovedTotalReviews
                };
            }
            if (productReview != null)
            {
                productReview.ProductId            = product.Id;
                productReview.AllowCustomerReviews = product.AllowCustomerReviews;
            }
            return(productReview);
        }