protected void PrepareProductReviewsModel(ProductReviewsModel model, Product product) { if (product == null) throw new ArgumentNullException("product"); if (model == null) throw new ArgumentNullException("model"); model.ProductId = product.Id; model.ProductName = product.GetLocalized(x => x.Name); model.ProductSeName = product.GetSeName(); var productReviews = product.ProductReviews.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc); foreach (var pr in productReviews) { var customer = pr.Customer; model.Items.Add(new ProductReviewModel() { Id = pr.Id, CustomerId = pr.CustomerId, CustomerName = customer.FormatUserName(), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(), Title = pr.Title, ReviewText = pr.ReviewText, Rating = pr.Rating, Helpfulness = new ProductReviewHelpfulnessModel() { ProductReviewId = pr.Id, HelpfulYesTotal = pr.HelpfulYesTotal, HelpfulNoTotal = pr.HelpfulNoTotal, }, WrittenOnStr = _dateTimeHelper.ConvertToUserTime(pr.CreatedOnUtc, DateTimeKind.Utc).ToString("g"), }); } model.AddProductReview.CanCurrentCustomerLeaveReview = _catalogSettings.AllowAnonymousUsersToReviewProduct || !_workContext.CurrentCustomer.IsGuest(); model.AddProductReview.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage; }
public virtual void AddProductTokens(IList<Token> tokens, Product product) { tokens.Add(new Token("Product.Name", product.Name)); tokens.Add(new Token("Product.ShortDescription", product.ShortDescription, true)); //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) var productUrl = string.Format("{0}{1}", _webHelper.GetStoreLocation(false), product.GetSeName()); tokens.Add(new Token("Product.ProductURLForCustomer", productUrl, true)); //event notification _eventPublisher.EntityTokensAdded(product, tokens); }
protected ProductDetailsModel PrepareProductDetailsPageModel(Product product) { if (product == null) throw new ArgumentNullException("product"); var model = new ProductDetailsModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), MetaKeywords = product.GetLocalized(x => x.MetaKeywords), MetaDescription = product.GetLocalized(x => x.MetaDescription), MetaTitle = product.GetLocalized(x => x.MetaTitle), SeName = product.GetSeName(), }; //template var templateCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_TEMPLATE_MODEL_KEY, product.ProductTemplateId); model.ProductTemplateViewPath = _cacheManager.Get(templateCacheKey, () => { var template = _productTemplateService.GetProductTemplateById(product.ProductTemplateId); if (template == null) template = _productTemplateService.GetAllProductTemplates().FirstOrDefault(); if (template == null) throw new Exception("No default template could be loaded"); return template.ViewPath; }); //pictures model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled; var pictures = _pictureService.GetPicturesByProductId(product.Id); if (pictures.Any()) { //default picture model.DefaultPictureModel = new PictureModel() { ImageUrl = _pictureService.GetPictureUrl(pictures.FirstOrDefault(), _mediaSettings.ProductDetailsPictureSize), FullSizeImageUrl = _pictureService.GetPictureUrl(pictures.FirstOrDefault()), Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name), }; //all pictures foreach (var picture in pictures) { model.PictureModels.Add(new PictureModel() { ImageUrl = _pictureService.GetPictureUrl(picture, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage), FullSizeImageUrl = _pictureService.GetPictureUrl(picture), Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name), }); } } else { //no images. set the default one model.DefaultPictureModel = new PictureModel() { ImageUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.ProductDetailsPictureSize), FullSizeImageUrl = _pictureService.GetDefaultPictureUrl(), Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name), }; } //product variants foreach (var variant in _productService.GetProductVariantsByProductId(product.Id)) model.ProductVariantModels.Add(PrepareProductVariantModel(new ProductDetailsModel.ProductVariantModel(), variant)); return model; }