public ActionResult ProductPictureList(DataSourceRequest command, int productId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { var product = _productService.GetProductById(productId); if (product != null && product.VendorId != _workContext.CurrentVendor.Id) { return Content("This is not your product"); } } var productPictures = _productService.GetProductPicturesByProductId(productId); var productPicturesModel = productPictures .Select(x => { var picture = _pictureService.GetPictureById(x.PictureId); if (picture == null) throw new Exception("Picture cannot be loaded"); var m = new ProductModel.ProductPictureModel { Id = x.Id, ProductId = x.ProductId, PictureId = x.PictureId, PictureUrl = _pictureService.GetPictureUrl(picture), OverrideAltAttribute = picture.AltAttribute, OverrideTitleAttribute = picture.TitleAttribute, DisplayOrder = x.DisplayOrder }; return m; }) .ToList(); var gridModel = new DataSourceResult { Data = productPicturesModel, Total = productPicturesModel.Count }; return Json(gridModel); }
public ActionResult GetProductInfoForVendorIB(int productId) { var product = _productService.GetProductById(productId); var model = product.ToModel(); PrepareProductModel(model, product, false, false); AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = product.GetLocalized(x => x.Name, languageId, false, false); locale.ShortDescription = product.GetLocalized(x => x.ShortDescription, languageId, false, false); locale.FullDescription = product.GetLocalized(x => x.FullDescription, languageId, false, false); locale.MetaKeywords = product.GetLocalized(x => x.MetaKeywords, languageId, false, false); locale.MetaDescription = product.GetLocalized(x => x.MetaDescription, languageId, false, false); locale.MetaTitle = product.GetLocalized(x => x.MetaTitle, languageId, false, false); locale.SeName = product.GetSeName(languageId, false, false); }); PrepareAclModel(model, product, false); PrepareStoresMappingModel(model, product, false); var productPictures = _productService.GetProductPicturesByProductId(product.Id); var productPicturesModel = productPictures .Select(x => { var picture = _pictureService.GetPictureById(x.PictureId); if (picture == null) throw new Exception("Picture cannot be loaded"); var m = new ProductModel.ProductPictureModel { Id = x.Id, ProductId = x.ProductId, PictureId = x.PictureId, PictureUrl = _pictureService.GetPictureUrl(picture), OverrideAltAttribute = picture.AltAttribute, OverrideTitleAttribute = picture.TitleAttribute, DisplayOrder = x.DisplayOrder }; return m; }) .ToList(); model.ProductPictureModels = productPicturesModel; var productDetail = this.RenderPartialViewToString("_ProductInforForVendor", model); return Json( new{ success = true, // JsonRequestBehavior.AllowGet, message = string.Format(_localizationService.GetResource("Products.ProductHasBeenAddedToTheCart.Link"), Url.RouteUrl("ShoppingCart")), productDetailsHtml = productDetail, }); }
public ActionResult EditIB(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var product = _productService.GetProductById(id); if (product == null || product.Deleted) //No product found with the specified id return RedirectToAction("List"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id) return RedirectToAction("List"); var model = product.ToModel(); PrepareProductModel(model, product, false, false); AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = product.GetLocalized(x => x.Name, languageId, false, false); locale.ShortDescription = product.GetLocalized(x => x.ShortDescription, languageId, false, false); locale.FullDescription = product.GetLocalized(x => x.FullDescription, languageId, false, false); locale.MetaKeywords = product.GetLocalized(x => x.MetaKeywords, languageId, false, false); locale.MetaDescription = product.GetLocalized(x => x.MetaDescription, languageId, false, false); locale.MetaTitle = product.GetLocalized(x => x.MetaTitle, languageId, false, false); locale.SeName = product.GetSeName(languageId, false, false); }); PrepareAclModel(model, product, false); PrepareStoresMappingModel(model, product, false); var productPictures = _productService.GetProductPicturesByProductId(product.Id); var productPicturesModel = productPictures .Select(x => { var picture = _pictureService.GetPictureById(x.PictureId); if (picture == null) throw new Exception("Picture cannot be loaded"); var m = new ProductModel.ProductPictureModel { Id = x.Id, ProductId = x.ProductId, PictureId = x.PictureId, PictureUrl = _pictureService.GetPictureUrl(picture), OverrideAltAttribute = picture.AltAttribute, OverrideTitleAttribute = picture.TitleAttribute, DisplayOrder = x.DisplayOrder }; return m; }) .ToList(); model.ProductPictureModels = productPicturesModel; return View(model); }
public ActionResult EditIB(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var product = _productService.GetProductById(id); if (product == null || product.Deleted) //No product found with the specified id return RedirectToAction("List"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id) return RedirectToAction("List"); var model = product.ToModel(); PrepareProductModel(model, product, false, false); AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = product.GetLocalized(x => x.Name, languageId, false, false); locale.ShortDescription = product.GetLocalized(x => x.ShortDescription, languageId, false, false); locale.FullDescription = product.GetLocalized(x => x.FullDescription, languageId, false, false); locale.MetaKeywords = product.GetLocalized(x => x.MetaKeywords, languageId, false, false); locale.MetaDescription = product.GetLocalized(x => x.MetaDescription, languageId, false, false); locale.MetaTitle = product.GetLocalized(x => x.MetaTitle, languageId, false, false); locale.SeName = product.GetSeName(languageId, false, false); }); PrepareAclModel(model, product, false); PrepareStoresMappingModel(model, product, false); var productPictures = _productService.GetProductPicturesByProductId(product.Id); var productPicturesModel = productPictures .Select(x => { var picture = _pictureService.GetPictureById(x.PictureId); if (picture == null) throw new Exception("Picture cannot be loaded"); var m = new ProductModel.ProductPictureModel { Id = x.Id, ProductId = x.ProductId, PictureId = x.PictureId, PictureUrl = _pictureService.GetPictureUrl(picture), OverrideAltAttribute = picture.AltAttribute, OverrideTitleAttribute = picture.TitleAttribute, DisplayOrder = x.DisplayOrder }; return m; }) .ToList(); model.ProductPictureModels = productPicturesModel; var categoriesModel = new List<CategoryModel>(); //all categories var allCategories = _categoryService.GetAllCategories(); foreach (var c in allCategories) { //generate full category name (breadcrumb) string categoryBreadcrumb = ""; var breadcrumb = c.GetCategoryBreadCrumb(allCategories, _aclService, _storeMappingService); for (int i = 0; i <= breadcrumb.Count - 1; i++) { categoryBreadcrumb += breadcrumb[i].GetLocalized(x => x.Name); if (i != breadcrumb.Count - 1) categoryBreadcrumb += " >> "; } categoriesModel.Add(new CategoryModel { Id = c.Id, Breadcrumb = categoryBreadcrumb }); } var styles = _customDataService.GetCustomDataByKeyGroup(CustomDataKeyGroupNames.Style); var materials = _customDataService.GetCustomDataByKeyGroup(CustomDataKeyGroupNames.Material); model.Styles = (from st in styles select new SelectListItem { Text = st.Value, Value = st.Key }).OrderBy(v => v.Value).ToList(); model.Materials = (from cd in materials select new SelectListItem { Text = cd.Value, Value = cd.Key }).OrderBy(v => v.Value).ToList(); var extCat = _categoryService.GetProductCategoriesByProductId(product.Id, true); if (extCat != null && extCat.Count>0) { model.CategoryId = extCat[0].CategoryId; } model.AvailableCategories = categoriesModel.Select(c => new SelectListItem { Text = c.Breadcrumb, Value = c.Id.ToString(),Selected=c.Id== model.CategoryId }).ToList(); model.Categories = categoriesModel; if (_workContext.CurrentVendor != null) model.VendorId = _workContext.CurrentVendor.Id; return View(model); }