Exemple #1
0
        public ActionResult ProductDetails(string urlkey)
        {
            var product = _productService.GetProductOverviewModelByUrlRewrite(urlkey);

            // If the product is not found, then return 404
            if (product == null || product.VisibleIndividually == false)
            {
                return(RedirectToRoute("Product Not Found"));
            }

            // If product is disabled, show alternative products
            if (product.Enabled == false)
            {
                return(View("ProductNotAvailable", new ProductNotAvailableModel {
                    ProductId = product.Id, Name = product.Name
                }));
            }

            _recentlyViewedProductsService.AddProductToRecentlyViewedList(product.Id);

            // Prepare the model
            var model = PrepareProductDetailsModel(product);

            return(View(model));
        }
        public ActionResult ProductDetails(int productId, string attributes)
        {
            var product = _productService.GetProductById(productId);

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

            //Is published?
            //Check whether the current user has a "Manage catalog" permission
            //It allows him to preview a product before publishing
            if (!product.Published && !_services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(HttpNotFound());
            }

            //ACL (access control list)
            if (!_aclService.Authorize(product))
            {
                return(HttpNotFound());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(product))
            {
                return(HttpNotFound());
            }

            //visible individually?
            if (!product.VisibleIndividually)
            {
                //is this one an associated products?
                var parentGroupedProduct = _productService.GetProductById(product.ParentGroupedProductId);
                if (parentGroupedProduct != null)
                {
                    return(RedirectToRoute("Product", new { SeName = parentGroupedProduct.GetSeName() }));
                }
                else
                {
                    return(HttpNotFound());
                }
            }

            //prepare the model
            var selectedAttributes = new FormCollection();

            selectedAttributes.ConvertAttributeQueryData(_productAttributeParser.DeserializeQueryData(attributes), product.Id);

            var model = _helper.PrepareProductDetailsPageModel(product, selectedAttributes: selectedAttributes);

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

            //activity log
            _services.CustomerActivity.InsertActivity("PublicStore.ViewProduct", T("ActivityLog.PublicStore.ViewProduct"), product.Name);

            return(View(model.ProductTemplateViewPath, model));
        }
Exemple #3
0
        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 async Task <IActionResult> ProductDetails(int productId, ProductVariantQuery query)
        {
            var product = await _db.Products.FindByIdAsync(productId, false);

            if (product == null || product.Deleted || product.IsSystemProduct)
            {
                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 && !await Services.Permissions.AuthorizeAsync(Permissions.Catalog.Product.Read))
            {
                return(NotFound());
            }

            // ACL (access control list).
            if (!await _aclService.AuthorizeAsync(product))
            {
                return(NotFound());
            }

            // Store mapping.
            if (!await _storeMappingService.AuthorizeAsync(product))
            {
                return(NotFound());
            }

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

            // Activity log
            Services.ActivityLogger.LogActivity("PublicStore.ViewProduct", T("ActivityLog.PublicStore.ViewProduct"), product.Name);

            // TODO: (mh) (core) Continue CatalogController.Category()

            var store = Services.StoreContext.CurrentStore;
            var price = Services.CurrencyService.ConvertToWorkingCurrency(product.Price);

            return(Content($"Product --> Id: {product.Id}, Name: {product.Name}, Price: {price}"));
        }
Exemple #5
0
        public virtual async Task <IActionResult> ProductDetails(string productId, string updatecartitemid = "")
        {
            var product = await _productService.GetProductById(productId);

            if (product == null)
            {
                return(InvokeHttp404());
            }

            var customer = _workContext.CurrentCustomer;

            //published?
            if (!_catalogSettings.AllowViewUnpublishedProductPage)
            {
                //Check whether the current user has a "Manage catalog" permission
                //It allows him to preview a product before publishing
                if (!product.Published && !await _permissionService.Authorize(StandardPermissionProvider.ManageProducts, customer))
                {
                    return(InvokeHttp404());
                }
            }

            //ACL (access control list)
            if (!_aclService.Authorize(product, customer))
            {
                return(InvokeHttp404());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(product))
            {
                return(InvokeHttp404());
            }

            //availability dates
            if (!product.IsAvailable() && !(product.ProductType == ProductType.Auction))
            {
                return(InvokeHttp404());
            }

            //visible individually?
            if (!product.VisibleIndividually)
            {
                //is this one an associated products?
                var parentGroupedProduct = await _productService.GetProductById(product.ParentGroupedProductId);

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

                return(RedirectToRoute("Product", new { SeName = parentGroupedProduct.GetSeName(_workContext.WorkingLanguage.Id) }));
            }
            //update existing shopping cart item?
            ShoppingCartItem updatecartitem = null;

            if (_shoppingCartSettings.AllowCartItemEditing && !String.IsNullOrEmpty(updatecartitemid))
            {
                var cart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id);

                updatecartitem = cart.FirstOrDefault(x => x.Id == updatecartitemid);
                //not found?
                if (updatecartitem == null)
                {
                    return(RedirectToRoute("Product", new { SeName = product.GetSeName(_workContext.WorkingLanguage.Id) }));
                }
                //is it this product?
                if (product.Id != updatecartitem.ProductId)
                {
                    return(RedirectToRoute("Product", new { SeName = product.GetSeName(_workContext.WorkingLanguage.Id) }));
                }
            }

            //prepare the model
            var model = await _mediator.Send(new GetProductDetailsPage()
            {
                Store               = _storeContext.CurrentStore,
                Product             = product,
                IsAssociatedProduct = false,
                UpdateCartItem      = updatecartitem
            });

            //product template
            var productTemplateViewPath = await _mediator.Send(new GetProductTemplateViewPath()
            {
                ProductTemplateId = product.ProductTemplateId
            });

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

            //display "edit" (manage) link
            if (await _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel, customer) &&
                await _permissionService.Authorize(StandardPermissionProvider.ManageProducts, customer))
            {
                //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
            await _customerActivityService.InsertActivity("PublicStore.ViewProduct", product.Id, _localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name);

            await _customerActionEventService.Viewed(customer, this.HttpContext.Request.Path.ToString(), this.Request.Headers[HeaderNames.Referer].ToString() != null?Request.Headers[HeaderNames.Referer].ToString() : "");

            await _productService.UpdateMostView(productId);

            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));
        }
Exemple #7
0
        public async Task <IActionResult> ProductDetails(int productId, ProductVariantQuery query)
        {
            var product = await _db.Products
                          .IncludeMedia()
                          .IncludeManufacturers()
                          .Where(x => x.Id == productId)
                          .FirstOrDefaultAsync();

            if (product == null || product.IsSystemProduct)
            {
                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 && !await Services.Permissions.AuthorizeAsync(Permissions.Catalog.Product.Read))
            {
                return(NotFound());
            }

            // ACL (access control list).
            if (!await _aclService.AuthorizeAsync(product))
            {
                return(NotFound());
            }

            // Store mapping.
            if (!await _storeMappingService.AuthorizeAsync(product))
            {
                return(NotFound());
            }

            // Is product individually visible?
            if (product.Visibility == ProductVisibility.Hidden)
            {
                // Find parent grouped product.
                var parentGroupedProduct = await _db.Products.FindByIdAsync(product.ParentGroupedProductId, false);

                if (parentGroupedProduct == null)
                {
                    return(NotFound());
                }

                var seName = await parentGroupedProduct.GetActiveSlugAsync();

                if (seName.IsEmpty())
                {
                    return(NotFound());
                }

                var routeValues = new RouteValueDictionary
                {
                    { "SeName", seName }
                };

                // Add query string parameters.
                Request.Query.Each(x => routeValues.Add(x.Key, Request.Query[x.Value].ToString()));

                return(RedirectToRoute("Product", routeValues));
            }

            // Prepare the view model
            var model = await _helper.MapProductDetailsPageModelAsync(product, query);

            // Some cargo data
            model.PictureSize            = _mediaSettings.ProductDetailsPictureSize;
            model.HotlineTelephoneNumber = _contactDataSettings.HotlineTelephoneNumber.NullEmpty();
            if (_seoSettings.CanonicalUrlsEnabled)
            {
                model.CanonicalUrl = _urlHelper.Value.RouteUrl("Product", new { model.SeName }, Request.Scheme);
            }

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

            // Activity log
            Services.ActivityLogger.LogActivity("PublicStore.ViewProduct", T("ActivityLog.PublicStore.ViewProduct"), product.Name);

            // Breadcrumb
            if (_catalogSettings.CategoryBreadcrumbEnabled)
            {
                await _helper.GetBreadcrumbAsync(_breadcrumb, ControllerContext, product);

                _breadcrumb.Track(new MenuItem
                {
                    Text     = model.Name,
                    Rtl      = model.Name.CurrentLanguage.Rtl,
                    EntityId = product.Id,
                    Url      = Url.RouteUrl("Product", new { model.SeName })
                });
            }

            return(View(model.ProductTemplateViewPath, model));
        }
        public ActionResult ProductDetails(int productId, string attributes, ProductVariantQuery query)
        {
            var product = _productService.GetProductById(productId);

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

            // Is published? Check whether the current user has a "Manage catalog" permission.
            // It allows him to preview a product before publishing.
            if (!product.Published && !_services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(HttpNotFound());
            }

            //ACL (access control list)
            if (!_aclService.Authorize(product))
            {
                return(HttpNotFound());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(product))
            {
                return(HttpNotFound());
            }

            // Is product individually visible?
            if (!product.VisibleIndividually)
            {
                // Find parent grouped product.
                var parentGroupedProduct = _productService.GetProductById(product.ParentGroupedProductId);

                if (parentGroupedProduct == null)
                {
                    return(HttpNotFound());
                }

                var routeValues = new RouteValueDictionary();
                routeValues.Add("SeName", parentGroupedProduct.GetSeName());

                // Add query string parameters.
                Request.QueryString.AllKeys.Each(x => routeValues.Add(x, Request.QueryString[x]));

                return(RedirectToRoute("Product", routeValues));
            }

            // Prepare the view model
            var model = _helper.PrepareProductDetailsPageModel(product, query);

            // Some cargo data
            model.PictureSize          = _mediaSettings.ProductDetailsPictureSize;
            model.CanonicalUrlsEnabled = _seoSettings.CanonicalUrlsEnabled;

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

            // Activity log
            _services.CustomerActivity.InsertActivity("PublicStore.ViewProduct", T("ActivityLog.PublicStore.ViewProduct"), product.Name);

            // Breadcrumb
            if (_catalogSettings.CategoryBreadcrumbEnabled)
            {
                _helper.GetCategoryBreadCrumb(0, productId).Select(x => x.Value).Each(x => _breadcrumb.Track(x));
                _breadcrumb.Track(new MenuItem
                {
                    Text     = model.Name,
                    Rtl      = model.Name.CurrentLanguage.Rtl,
                    EntityId = product.Id,
                    Url      = Url.RouteUrl("Product", new { productId = product.Id, SeName = model.SeName })
                });
            }

            return(View(model.ProductTemplateViewPath, model));
        }
Exemple #9
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));
        }
Exemple #10
0
        ////[GrandHttpsRequirement(SslRequirement.No)]
        public virtual IActionResult ProductDetails(string productId, string updatecartitemid = "")
        {
            var product = _productService.GetProductById(productId);

            if (product == null)
            {
                return(InvokeHttp404());
            }
            //published?
            if (!_catalogSettings.AllowViewUnpublishedProductPage)
            {
                //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(InvokeHttp404());
                }
            }

            //ACL (access control list)
            if (!_aclService.Authorize(product))
            {
                return(InvokeHttp404());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(product))
            {
                return(InvokeHttp404());
            }

            //availability dates
            if (!product.IsAvailable())
            {
                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 item?
            ShoppingCartItem updatecartitem = null;

            if (_shoppingCartSettings.AllowCartItemEditing && !String.IsNullOrEmpty(updatecartitemid))
            {
                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() }));
                }
            }

            //prepare the model
            var model = _productWebService.PrepareProductDetailsPage(product, updatecartitem, false);

            //product template
            var productTemplateViewPath = _productWebService.PrepareProductTemplateViewPath(product.ProductTemplateId);

            //save as recently viewed
            _recentlyViewedProductsService.AddProductToRecentlyViewedList(_workContext.CurrentCustomer.Id, 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", product.Id, _localizationService.GetResource("ActivityLog.PublicStore.ViewProduct"), product.Name);

            //tbh
            //_customerActionEventService.Viewed(_workContext.CurrentCustomer, Request.Url.ToString(), Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "");
            _productService.UpdateMostView(productId, 1);

            return(View(productTemplateViewPath, model));
        }
Exemple #11
0
        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());
        }