public virtual ActionResult ProductReviews(int productId)
        {
            var product = _productService.GetProductById(productId);

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

            var model = new ProductReviewsModel();

            model = _productModelFactory.PrepareProductReviewsModel(model, product);
            //only registered users can leave reviews
            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing &&
                !_orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, productId: productId, osIds: new List <int> {
                (int)OrderStatus.Complete
            }).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
            }

            //default value
            model.AddProductReview.Rating = _catalogSettings.DefaultProductRatingValue;
            return(View(model));
        }
        public virtual IActionResult ProductReviews(int productId)
        {
            var product = _productService.GetProductById(productId);

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

            var model = new ProductReviewsModel();

            model = _productModelFactory.PrepareProductReviewsModel(model, product);
            //only registered users can leave reviews
            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            //default value
            model.AddProductReview.Rating = _catalogSettings.DefaultProductRatingValue;

            //default value for all additional review types
            if (model.ReviewTypeList.Count > 0)
            {
                foreach (var additionalProductReview in model.AddAdditionalProductReviewList)
                {
                    additionalProductReview.Rating = additionalProductReview.IsRequired ? _catalogSettings.DefaultProductRatingValue : 0;
                }
            }

            return(View(model));
        }
Example #3
0
        public virtual IActionResult StoreReviews()
        {
            var product = _productService.GetProductById(1);

            if (product == null)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!int.TryParse(_webHelper.QueryString <string>("period"), out int period))
            {
                period = 12;
            }
            ViewBag.Period = period;

            var model = new ProductReviewsModel();

            model = _productModelFactory.PrepareProductReviewsModel(model, product, period);

            //default value
            model.AddProductReview.Rating = _catalogSettings.DefaultProductRatingValue;

            //default value for all additional review types
            if (model.ReviewTypeList.Count > 0)
            {
                foreach (var additionalProductReview in model.AddAdditionalProductReviewList)
                {
                    additionalProductReview.Rating = additionalProductReview.IsRequired ? _catalogSettings.DefaultProductRatingValue : 0;
                }
            }

            ViewBag.CustomerId = _workContext.CurrentCustomer.Id;

            return(View(model));
        }
        public virtual IActionResult ProductReviews(int productId)
        {
            var product = _productService.GetProductById(productId);

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

            var model = new ProductReviewsModel();

            model = _productModelFactory.PrepareProductReviewsModel(model, product);
            //only registered users can leave reviews
            if (_customerService.IsGuest(_workContext.CurrentCustomer) && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing)
            {
                var hasCompletedOrders = _orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id,
                                                                    productId: productId,
                                                                    osIds: new List <int> {
                    (int)OrderStatus.Complete
                },
                                                                    pageSize: 1).Any();
                if (!hasCompletedOrders)
                {
                    ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
                }
            }

            //default value
            model.AddProductReview.Rating = _catalogSettings.DefaultProductRatingValue;

            model.AddProductReview.CanAddNewReview = _productService.CanAddReview(product.Id, _storeContext.CurrentStore.Id);

            //default value for all additional review types
            if (model.ReviewTypeList.Count > 0)
            {
                foreach (var additionalProductReview in model.AddAdditionalProductReviewList)
                {
                    additionalProductReview.Rating = additionalProductReview.IsRequired ? _catalogSettings.DefaultProductRatingValue : 0;
                }
            }

            return(View(model));
        }
Example #5
0
        public virtual IActionResult ProductDetails(string SeName, int updatecartitemid = 0)//int productId, int updatecartitemid = 0)
        {
            var productId = _productService.GetProductIdBySeName(SeName);
            var product   = _productService.GetProductById(productId);

            if (product == null || product.Deleted || product.StatusId == 3 || product.StatusId == 5)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                (!product.Published && !_catalogSettings.AllowViewUnpublishedProductPage) ||
                //ACL (access control list)
                !_aclService.Authorize(product) ||
                //Store mapping
                !_storeMappingService.Authorize(product) ||
                //availability dates
                !_productService.ProductIsAvailable(product);

            //Check whether the current user has a "Manage products" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            if (notAvailable && !_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(InvokeHttp404());
            }

            //visible individually?
            if (!product.VisibleIndividually)
            {
                //is this one an associated products?
                var parentGroupedProduct = _productService.GetProductById(product.ParentGroupedProductId);
                if (parentGroupedProduct == null)
                {
                    return(RedirectToRoute("HomePage"));
                }

                return(RedirectToRoute("Product", new { SeName = _urlRecordService.GetSeName(parentGroupedProduct) }));
            }

            //update existing shopping cart or wishlist  item?
            ShoppingCartItem updatecartitem = null;

            if (_shoppingCartSettings.AllowCartItemEditing && updatecartitemid > 0)
            {
                var cart = _workContext.CurrentCustomer.ShoppingCartItems
                           .LimitPerStore(_storeContext.CurrentStore.Id);
                updatecartitem = cart.FirstOrDefault(x => x.Id == updatecartitemid);
                //not found?
                if (updatecartitem == null)
                {
                    return(RedirectToRoute("Product", new { SeName = _urlRecordService.GetSeName(product) }));
                }
                //is it this product?
                if (product.Id != updatecartitem.ProductId)
                {
                    return(RedirectToRoute("Product", new { SeName = _urlRecordService.GetSeName(product) }));
                }
            }

            //save as recently viewed
            _recentlyViewedProductsService.AddProductToRecentlyViewedList(product.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) &&
                _permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                //a vendor should have access only to his products
                if (_workContext.CurrentVendor == null || _workContext.CurrentVendor.Id == product.VendorId)
                {
                    DisplayEditLink(Url.Action("Edit", "Product", new { id = product.Id, area = AreaNames.Admin }));
                }
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewProduct",
                                                    string.Format(_localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name), product);

            //model
            var model = _productModelFactory.PrepareProductDetailsModel(product, updatecartitem, false, false);

            model.SeName = SeName;

            //reviews
            model.Reviews = new ProductReviewsModel();
            model.Reviews = _productModelFactory.PrepareProductReviewsModel(model.Reviews, product);

            if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing)
            {
                var hasCompletedOrders = _orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id,
                                                                    productId: productId,
                                                                    osIds: new List <int> {
                    (int)OrderStatus.Complete
                },
                                                                    pageSize: 1).Any();
                if (!hasCompletedOrders)
                {
                    ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
                }
            }

            //default value
            model.Reviews.AddProductReview.Rating = _catalogSettings.DefaultProductRatingValue;

            //default value for all additional review types
            if (model.Reviews.ReviewTypeList.Count > 0)
            {
                foreach (var additionalProductReview in model.Reviews.AddAdditionalProductReviewList)
                {
                    additionalProductReview.Rating = additionalProductReview.IsRequired ? _catalogSettings.DefaultProductRatingValue : 0;
                }
            }

            var activeCategory    = product.ProductCategories.FirstOrDefault(x => x.Category.ParentCategoryId == 0)?.CategoryId;
            var activeSubCategory = product.ProductCategories.FirstOrDefault(x => x.Category.ParentCategoryId == activeCategory)?.CategoryId;

            ViewBag.ActiveCategory    = activeCategory;
            ViewBag.ActiveSubCategory = activeSubCategory;
            //template
            var productTemplateViewPath = _productModelFactory.PrepareProductTemplateViewPath(product);

            return(View(productTemplateViewPath, model));
        }
        public virtual IActionResult ProductDetails(int productId, int updatecartitemid = 0)
        {
            var product = _productService.GetProductById(productId);

            if (product == null || product.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                (!product.Published && !_catalogSettings.AllowViewUnpublishedProductPage) ||
                //ACL (access control list)
                !_aclService.Authorize(product) ||
                //Store mapping
                !_storeMappingService.Authorize(product) ||
                //availability dates
                !product.IsAvailable();

            //Check whether the current user has a "Manage products" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            if (notAvailable && !_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(InvokeHttp404());
            }

            //visible individually?
            if (!product.VisibleIndividually)
            {
                //is this one an associated products?
                var parentGroupedProduct = _productService.GetProductById(product.ParentGroupedProductId);
                if (parentGroupedProduct == null)
                {
                    return(RedirectToRoute("HomePage"));
                }

                return(RedirectToRoute("Product", new { SeName = parentGroupedProduct.GetSeName() }));
            }

            //update existing shopping cart or wishlist  item?
            ShoppingCartItem updatecartitem = null;

            if (_shoppingCartSettings.AllowCartItemEditing && updatecartitemid > 0)
            {
                var cart = _workContext.CurrentCustomer.ShoppingCartItems
                           .LimitPerStore(_storeContext.CurrentStore.Id)
                           .ToList();
                updatecartitem = cart.FirstOrDefault(x => x.Id == updatecartitemid);
                //not found?
                if (updatecartitem == null)
                {
                    return(RedirectToRoute("Product", new { SeName = product.GetSeName() }));
                }
                //is it this product?
                if (product.Id != updatecartitem.ProductId)
                {
                    return(RedirectToRoute("Product", new { SeName = product.GetSeName() }));
                }
            }

            //save as recently viewed
            _recentlyViewedProductsService.AddProductToRecentlyViewedList(product.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) &&
                _permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                //a vendor should have access only to his products
                if (_workContext.CurrentVendor == null || _workContext.CurrentVendor.Id == product.VendorId)
                {
                    DisplayEditLink(Url.Action("Edit", "Product", new { id = product.Id, area = AreaNames.Admin }));
                }
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewProduct", _localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name);

            //model
            var model   = _productModelFactory.PrepareProductDetailsModel(product, updatecartitem, false);
            var reviews = new ProductReviewsModel();

            model.ProductReviewsModel = _productModelFactory.PrepareProductReviewsModel(reviews, product);
            //template
            var productTemplateViewPath = _productModelFactory.PrepareProductTemplateViewPath(product);

            return(View(productTemplateViewPath, model));
        }