Esempio n. 1
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));
        }
        private ProductDetailsModel GetProductDetails(int productId, int updateCartItemId = 0)
        {
            var controllerContext = new ControllerContext();
            var product           = _productService.GetProductById(productId);
            var cart = _workContext.CurrentCustomer.ShoppingCartItems
                       .LimitPerStore(_storeContext.CurrentStore.Id).ToList();
            var updatecartitem = cart.FirstOrDefault(x => x.Id == updateCartItemId);
            var model          = _productModelFactory.PrepareProductDetailsModel(product, updatecartitem, false);

            // add hidden specification params
            // which checked as "don't show on product page"
            model.ProductSpecifications =
                _specificationAttributeService.GetProductSpecificationAttributes(productId, 0, null, null)
                .Select(psa =>
            {
                var m = new ProductSpecificationModel
                {
                    SpecificationAttributeId   = psa.SpecificationAttributeOption.SpecificationAttributeId,
                    SpecificationAttributeName = psa.SpecificationAttributeOption.SpecificationAttribute
                                                 .GetLocalized(x => x.Name),
                    ColorSquaresRgb = psa.SpecificationAttributeOption.ColorSquaresRgb
                };

                switch (psa.AttributeType)
                {
                case SpecificationAttributeType.Option:
                    m.ValueRaw =
                        WebUtility.HtmlEncode(psa.SpecificationAttributeOption.GetLocalized(x => x.Name));
                    break;

                case SpecificationAttributeType.CustomText:
                    m.ValueRaw = WebUtility.HtmlEncode(psa.CustomValue);
                    break;

                case SpecificationAttributeType.CustomHtmlText:
                    m.ValueRaw = psa.CustomValue;
                    break;

                case SpecificationAttributeType.Hyperlink:
                    m.ValueRaw = string.Format("<a href='{0}' target='_blank'>{0}</a>", psa.CustomValue);
                    break;

                default:
                    break;
                }
                return(m);
            })
                .ToList();
            return(model);
        }
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product product = _productService.GetProductDetails((int)id);

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

            var productModel = _productModelFactory.PrepareProductDetailsModel(product);

            return(View(productModel));
        }
        public IViewComponentResult Invoke()
        {
            var products = _productService.SearchProducts().Where(x => x.OldPrice > x.Price &&
                                                                  x.AvailableEndDateTimeUtc - DateTime.Now > new TimeSpan(0)).ToList();
            var model = new List <ProductDetailsModel>();

            if (!products.Any())
            {
                return(Content(""));
            }
            foreach (var product in products)
            {
                model.Add(_productModelFactory.PrepareProductDetailsModel(product, null, false));
            }
            //var model = _productModelFactory.PrepareProductOverviewModels(products, true, true).ToList();

            return(View(model));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        //[HttpPost]
        //public IActionResult Index(ProductFilterViewModel filterModel)
        //{
        //    var products = _productModelFactory.PrepareProductmodel(filterModel);
        //    var xx = RenderPartialViewToString("_ProductList", products);

        //    return Json(new { success = true, view = xx });
        //}

        public IActionResult ProductDetails(int id)
        {
            var model = _productModelFactory.PrepareProductDetailsModel(id);

            return(View(model));
        }
Esempio n. 9
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());
        }