Beispiel #1
0
        private void InsertProductComment(ProductCommentsModel productCommentsModel, Product product)
        {
            bool           productCommentsMustBeApproved = !_productCommentsSetting.ProductCommentsMustBeApproved;
            ProductComment productComment = new ProductComment()
            {
                ProductId       = product.Id,
                CustomerId      = _workContext.CurrentCustomer.Id,
                CommentText     = productCommentsModel.AddProductComment.CommentText,
                HelpfulYesTotal = 0,
                HelpfulNoTotal  = 0,
                IsApproved      = productCommentsMustBeApproved,
                CreatedOnUtc    = DateTime.UtcNow,
                StoreId         = _storeContext.CurrentStore.Id,
                Visited         = false
            };

            _productCommentService.InsertProductComment(productComment);

            _productCommentModelFactory.PrepareProductCommentsModel(productCommentsModel, product);
            productCommentsModel.AddProductComment.CommentText       = null;
            productCommentsModel.AddProductComment.SuccessfullyAdded = true;
            if (!productCommentsMustBeApproved)
            {
                productCommentsModel.AddProductComment.Result = _localizationService.GetResource("Comments.SeeAfterApproving");
                return;
            }
            productCommentsModel.AddProductComment.Result = _localizationService.GetResource("Comments.SuccessfullyAdded");
        }
Beispiel #2
0
        public IViewComponentResult Invoke(string widgetZone, object additionalData)
        {
            if (additionalData == null)
            {
                return(Content(""));
            }

            var product = _productService.GetProductById((int)additionalData);

            if (product == null || product.Deleted || !product.Published)
            {
                return(Content(""));
            }

            if (!_productCommentsSetting.EnablePlugin)
            {
                return(Content(""));
            }

            var model = new ProductCommentsModel();

            _productCommentModelFactory.PrepareProductCommentsModel(model, product);
            //only registered users can leave comments
            if (_workContext.CurrentCustomer.IsGuest() && !_productCommentsSetting.AllowAnonymousUsersToCommentProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Comments.OnlyRegisteredUsersCanWriteComments"));
            }

            return(View("~/Plugins/Resanehlab.ProductComments/Views/_ProductComments.cshtml", model));
        }