public virtual ActionResult ProductDetails(int productId) { 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); //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() })); } //save as recently viewed _recentlyViewedProductsService.AddProductToRecentlyViewedList(product.Id); //display "edit" (manage) link if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { DisplayEditLink(Url.Action("Edit", "Product", new { id = product.Id, area = "Admin" })); } //activity log _customerActivityService.InsertActivity("PublicStore.ViewProduct", _localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name); //model var model = _productModelFactory.PrepareProductDetailsModel(product); //template var productTemplateViewPath = _productModelFactory.PrepareProductTemplateViewPath(product); return(View(productTemplateViewPath, model)); }
public virtual ActionResult 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 = "Admin" })); } } //activity log _customerActivityService.InsertActivity("PublicStore.ViewProduct", _localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name); //model var model = _productModelFactory.PrepareProductDetailsModel(product, updatecartitem, false); //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 !_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 var hasAdminAccess = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageProducts); if (notAvailable && !hasAdminAccess) { 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 = _shoppingCartService.GetShoppingCart(_workContext.CurrentCustomer, storeId: _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 and manage calendar link string manageCalendarUrl = string.Empty; if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { if (_workContext.CurrentVendor == null) { DisplayEditLink(Url.Action("Edit", "Product", new { id = product.Id, area = AreaNames.Admin })); } else if (_workContext.CurrentVendor.Id == product.VendorId) { //a vendor should have access only to his products manageCalendarUrl = Url.Action("AppointmentCalendar", "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); model.IsUserAuthenticated = _workContext.CurrentCustomer.IsRegistered(); model.ManageCalendarUrl = manageCalendarUrl; //template var productTemplateViewPath = _productModelFactory.PrepareProductTemplateViewPath(product); return(View(productTemplateViewPath, model)); }
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 ActionResult ProductDetails(int productId, int updatecartitemid = 0) { var product = _productService.GetProductById(productId); if (product == null || product.Deleted) { return(NotFound()); } //Is published? //Check whether the current user has a "Manage catalog" permission //It allows him to preview a product before publishing if (!product.Published && !_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(NotFound()); } //ACL (access control list) if (!_aclService.Authorize(product)) { return(NotFound()); } //Store mapping if (!_storeMappingService.Authorize(product)) { return(NotFound()); } //visible individually? if (!product.VisibleIndividually) { //is this one an associated products? var parentGroupedProduct = _productService.GetProductById(product.ParentGroupedProductId); if (parentGroupedProduct != null) { product = parentGroupedProduct; } else { return(NotFound()); } } //update existing shopping cart item? ShoppingCartItem updatecartitem = null; if (_shoppingCartSettings.AllowCartItemEditing && updatecartitemid > 0) { var cart = _workContext.CurrentCustomer.ShoppingCartItems .Where(x => x.ShoppingCartType == ShoppingCartType.ShoppingCart) .LimitPerStore(_storeContext.CurrentStore.Id) .ToList(); updatecartitem = cart.FirstOrDefault(x => x.Id == updatecartitemid); //not found? if (updatecartitem == null) { return(NotFound()); // return RedirectToRoute("Product", new { SeName = product.GetSeName() }); } //is it this product? if (product.Id != updatecartitem.ProductId) { return(NotFound()); // return RedirectToRoute("Product", new { SeName = product.GetSeName() }); } } //model var model = _productModelFactory.PrepareProductDetailsModel(product, updatecartitem, false); //template var productTemplateViewPath = _productModelFactory.PrepareProductTemplateViewPath(product); //save as recently viewed _recentlyViewedProductsService.AddProductToRecentlyViewedList(product.Id); //activity log _customerActivityService.InsertActivity("PublicStore.ViewProduct", _localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name); var bsQuickViewModel = new BsQuickViewModel(); bsQuickViewModel.ProductDetailsModel = model; var settingsModel = new BsQuickViewSettingsModel(); var quickViewsettings = _settingService.LoadSetting <QuickViewSettings>(); settingsModel.ButtonContainerName = quickViewsettings.ButtonContainerName; settingsModel.EnableWidget = quickViewsettings.EnableWidget; settingsModel.ShowAlsoPurchased = quickViewsettings.ShowAlsoPurchased; settingsModel.ShowRelatedProducts = quickViewsettings.ShowRelatedProducts; settingsModel.EnableEnlargePicture = quickViewsettings.EnableEnlargePicture; bsQuickViewModel.BsQuickViewSettingsModel = settingsModel; /*return View(model.ProductTemplateViewPath, model);*/ if (productTemplateViewPath.Equals("ProductTemplate.Simple")) { return(Json(new { html = this.RenderPartialViewToString("BsQuickView/QuickViewProductTemplate.Simple", bsQuickViewModel), })); //return View("QuickViewProductTemplate.Simple", bsQuickViewModel); } else if (productTemplateViewPath.Equals("ProductTemplate.Grouped")) { return(Json(new { html = this.RenderPartialViewToString("BsQuickView/QuickViewProductTemplate.Grouped", bsQuickViewModel), })); //return View("QuickViewProductTemplate.Grouped", bsQuickViewModel); } return(new NullJsonResult()); }