public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var model = new ProductListModel(); //a vendor should have access only to his products model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; //categories model.AvailableCategories.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); var categories = _categoryService.GetAllCategories(showHidden: true); foreach (var c in categories) model.AvailableCategories.Add(new SelectListItem { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() }); //manufacturers model.AvailableManufacturers.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var m in _manufacturerService.GetAllManufacturers(showHidden: true)) model.AvailableManufacturers.Add(new SelectListItem { Text = m.Name, Value = m.Id.ToString() }); //stores model.AvailableStores.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var s in _storeService.GetAllStores()) model.AvailableStores.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString() }); //warehouses model.AvailableWarehouses.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var wh in _shippingService.GetAllWarehouses()) model.AvailableWarehouses.Add(new SelectListItem { Text = wh.Name, Value = wh.Id.ToString() }); //vendors model.AvailableVendors.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var v in _vendorService.GetAllVendors(showHidden: true)) model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id.ToString() }); //product types model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList(); model.AvailableProductTypes.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"}); //"published" property //0 - all (according to "ShowHidden" parameter) //1 - published only //2 - unpublished only model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.All"), Value = "0" }); model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.PublishedOnly"), Value = "1" }); model.AvailablePublishedOptions.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly"), Value = "2" }); return View(model); }
public ActionResult ProductList(DataSourceRequest command, ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { model.SearchVendorId = _workContext.CurrentVendor.Id; } var categoryIds = new List<int> { model.SearchCategoryId }; //include subcategories if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); //0 - all (according to "ShowHidden" parameter) //1 - published only //2 - unpublished only bool? overridePublished = null; if (model.SearchPublishedId == 1) overridePublished = true; else if (model.SearchPublishedId == 2) overridePublished = false; var products = _productService.SearchProducts( categoryIds: categoryIds, manufacturerId: model.SearchManufacturerId, storeId: model.SearchStoreId, vendorId: model.SearchVendorId, warehouseId: model.SearchWarehouseId, productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId: null, keywords: model.SearchProductName, pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true, overridePublished: overridePublished ); var gridModel = new DataSourceResult(); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); //little hack here: //ensure that product full descriptions are not returned //otherwise, we can get the following error if products have too long descriptions: //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. " //also it improves performance productModel.FullDescription = ""; //picture var defaultProductPicture = _pictureService.GetPicturesByProductId(x.Id, 1).FirstOrDefault(); productModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true); //product type productModel.ProductTypeName = x.ProductType.GetLocalizedEnum(_localizationService, _workContext); //friendly stock qantity //if a simple product AND "manage inventory" is "Track inventory", then display if (x.ProductType == ProductType.SimpleProduct && x.ManageInventoryMethod == ManageInventoryMethod.ManageStock) productModel.StockQuantityStr = x.GetTotalStockQuantity().ToString(); return productModel; }); gridModel.Total = products.TotalCount; return Json(gridModel); }
public ActionResult ExportXmlAll(ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { model.SearchVendorId = _workContext.CurrentVendor.Id; } var categoryIds = new List<int> { model.SearchCategoryId }; //include subcategories if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); //0 - all (according to "ShowHidden" parameter) //1 - published only //2 - unpublished only bool? overridePublished = null; if (model.SearchPublishedId == 1) overridePublished = true; else if (model.SearchPublishedId == 2) overridePublished = false; var products = _productService.SearchProducts( categoryIds: categoryIds, manufacturerId: model.SearchManufacturerId, storeId: model.SearchStoreId, vendorId: model.SearchVendorId, warehouseId: model.SearchWarehouseId, productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, keywords: model.SearchProductName, showHidden: true, overridePublished: overridePublished ); try { var xml = _exportManager.ExportProductsToXml(products); return new XmlDownloadResult(xml, "products.xml"); } catch (Exception exc) { ErrorNotification(exc); return RedirectToAction("List"); } }
public ActionResult GoToSku(ProductListModel model) { string sku = model.GoDirectlyToSku; //try to load a product entity var product = _productService.GetProductBySku(sku); //if not found, then try to load a product attribute combination if (product == null) { var combination = _productAttributeService.GetProductAttributeCombinationBySku(sku); if (combination != null) { product = combination.Product; } } if (product != null) return RedirectToAction("Edit", "Product", new { id = product.Id }); //not found return List(); }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var model = new ProductListModel(); model.DisplayProductPictures = _adminAreaSettings.DisplayProductPictures; model.DisplayPdfDownloadCatalog = _pdfSettings.Enabled; //a vendor should have access only to his products model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; //categories model.AvailableCategories.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var c in _categoryService.GetAllCategories(showHidden: true)) model.AvailableCategories.Add(new SelectListItem() { Text = c.GetCategoryNameWithPrefix(_categoryService), Value = c.Id.ToString() }); //manufacturers model.AvailableManufacturers.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var m in _manufacturerService.GetAllManufacturers(true)) model.AvailableManufacturers.Add(new SelectListItem() { Text = m.Name, Value = m.Id.ToString() }); //stores model.AvailableStores.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var s in _storeService.GetAllStores()) model.AvailableStores.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }); //vendors model.AvailableVendors.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var v in _vendorService.GetAllVendors(0, int.MaxValue, true)) model.AvailableVendors.Add(new SelectListItem() { Text = v.Name, Value = v.Id.ToString() }); return View(model); }
public ActionResult DownloadCatalogAsPdf(ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { model.SearchVendorId = _workContext.CurrentVendor.Id; } var categoryIds = new List<int> { model.SearchCategoryId }; //include subcategories if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); //0 - all (according to "ShowHidden" parameter) //1 - published only //2 - unpublished only bool? overridePublished = null; if (model.SearchPublishedId == 1) overridePublished = true; else if (model.SearchPublishedId == 2) overridePublished = false; var products = _productService.SearchProducts( categoryIds: categoryIds, manufacturerId: model.SearchManufacturerId, storeId: model.SearchStoreId, vendorId: model.SearchVendorId, warehouseId: model.SearchWarehouseId, productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, keywords: model.SearchProductName, showHidden: true, overridePublished: overridePublished ); try { byte[] bytes; using (var stream = new MemoryStream()) { _pdfService.PrintProductsToPdf(stream, products); bytes = stream.ToArray(); } return File(bytes, "application/pdf", "pdfcatalog.pdf"); } catch (Exception exc) { ErrorNotification(exc); return RedirectToAction("List"); } }
public ActionResult ProductList(GridCommand command, ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { model.SearchVendorId = _workContext.CurrentVendor.Id; } var gridModel = new GridModel(); var products = _productService.SearchProducts( categoryIds: new List<int>() { model.SearchCategoryId }, manufacturerId: model.SearchManufacturerId, storeId: model.SearchStoreId, vendorId: model.SearchVendorId, keywords: model.SearchProductName, pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true ); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); PrepareProductPictureThumbnailModel(productModel, x); return productModel; }); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
public ActionResult GoToSku(ProductListModel model) { string sku = model.GoDirectlyToSku; var pv = _productService.GetProductVariantBySku(sku); if (pv != null) return RedirectToAction("Edit", "ProductVariant", new { id = pv.Id }); //not found return List(); }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); var model = new ProductListModel(); model.DisplayProductPictures = _adminAreaSettings.DisplayProductPictures; //a vendor should have access only to his products model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; //categories model.AvailableCategories.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); var categories = _categoryService.GetAllCategories(showHidden: true); foreach (var c in categories) model.AvailableCategories.Add(new SelectListItem() { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() }); //manufacturers model.AvailableManufacturers.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var m in _manufacturerService.GetAllManufacturers(showHidden: true)) model.AvailableManufacturers.Add(new SelectListItem() { Text = m.Name, Value = m.Id.ToString() }); //stores model.AvailableStores.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var s in _storeService.GetAllStores()) model.AvailableStores.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }); //stores model.AvailableWarehouses.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var wh in _shippingService.GetAllWarehouses()) model.AvailableWarehouses.Add(new SelectListItem() { Text = wh.Name, Value = wh.Id.ToString() }); //vendors model.AvailableVendors.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var v in _vendorService.GetAllVendors(0, int.MaxValue, true)) model.AvailableVendors.Add(new SelectListItem() { Text = v.Name, Value = v.Id.ToString() }); //product types model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList(); model.AvailableProductTypes.Insert(0, new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"}); return View(model); }
public ActionResult ProductList(DataSourceRequest command, ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) return AccessDeniedView(); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { model.SearchVendorId = _workContext.CurrentVendor.Id; } var categoryIds = new List<int>() { model.SearchCategoryId }; //include subcategories if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); var products = _productService.SearchProducts( categoryIds: categoryIds, manufacturerId: model.SearchManufacturerId, storeId: model.SearchStoreId, vendorId: model.SearchVendorId, warehouseId: model.SearchWarehouseId, productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId: null, keywords: model.SearchProductName, pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true ); var gridModel = new DataSourceResult(); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); //little hack here: //ensure that product full descriptions are not returned //otherwise, we can get the following error if products have too long descriptions: //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. " //also it improves performance productModel.FullDescription = ""; if (_adminAreaSettings.DisplayProductPictures) { var defaultProductPicture = _pictureService.GetPicturesByProductId(x.Id, 1).FirstOrDefault(); productModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true); } productModel.ProductTypeName = x.ProductType.GetLocalizedEnum(_localizationService, _workContext); return productModel; }); gridModel.Total = products.TotalCount; return Json(gridModel); }
public ActionResult ProductList(GridCommand command, ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var gridModel = new GridModel(); var products = _productService.SearchProducts(model.SearchCategoryId, model.SearchManufacturerId, null, null, null, 0, model.SearchProductName, false, _workContext.WorkingLanguage.Id, new List<int>(), ProductSortingEnum.Position, command.Page - 1, command.PageSize, true); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); PrepareProductPictureThumbnailModel(productModel, x); return productModel; }); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var products = _productService.SearchProducts(0, 0, null, null, null, 0, string.Empty, false, _workContext.WorkingLanguage.Id, new List<int>(), ProductSortingEnum.Position, 0, _adminAreaSettings.GridPageSize, true); var model = new ProductListModel(); model.DisplayProductPictures = _adminAreaSettings.DisplayProductPictures; model.Products = new GridModel<ProductModel> { Data = products.Select(x => { var productModel = x.ToModel(); PrepareProductPictureThumbnailModel(productModel, x); PrepareVariantsModel(productModel, x); return productModel; }), Total = products.TotalCount }; //categories model.AvailableCategories.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var c in _categoryService.GetAllCategories(true)) model.AvailableCategories.Add(new SelectListItem() { Text = c.GetCategoryNameWithPrefix(_categoryService), Value = c.Id.ToString() }); //manufacturers model.AvailableManufacturers.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var m in _manufacturerService.GetAllManufacturers(true)) model.AvailableManufacturers.Add(new SelectListItem() { Text = m.Name, Value = m.Id.ToString() }); return View(model); }
public ActionResult ProductList(GridCommand command, ProductListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog) && !_permissionService.Authorize(StandardPermissionProvider.ManageVendor) //add by hz ) return AccessDeniedView(); var gridModel = new GridModel(); int vendorToSearch = (customerVendorId > 0) ? customerVendorId : model.SearchVendorId;//add by hz IList<int> filterableSpecificationAttributeOptionIds = null; var products = _productService.SearchProducts(model.SearchCategoryId, model.SearchManufacturerId, vendorToSearch,//add by hz null, null, null, 0, model.SearchProductName, false, false, _workContext.WorkingLanguage.Id, new List<int>(), ProductSortingEnum.Position, command.Page - 1, command.PageSize, false, out filterableSpecificationAttributeOptionIds, true); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); PrepareProductPictureThumbnailModel(productModel, x); return productModel; }); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog) && !_permissionService.Authorize(StandardPermissionProvider.ManageVendor) //add by hz ) return AccessDeniedView(); IList<int> filterableSpecificationAttributeOptionIds = null; var products = _productService.SearchProducts(0, 0, customerVendorId, //add by hz null, null, null, 0, string.Empty, false, false, _workContext.WorkingLanguage.Id, new List<int>(), ProductSortingEnum.Position, 0, _adminAreaSettings.GridPageSize, false, out filterableSpecificationAttributeOptionIds, true); var model = new ProductListModel(); model.DisplayProductPictures = _adminAreaSettings.DisplayProductPictures; model.DisplayPdfDownloadCatalog = _pdfSettings.Enabled; model.Products = new GridModel<ProductModel> { Data = products.Select(x => { var productModel = x.ToModel(); PrepareProductPictureThumbnailModel(productModel, x); PrepareVariantsModel(productModel, x); return productModel; }), Total = products.TotalCount }; //categories model.AvailableCategories.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var c in _categoryService.GetAllCategories(showHidden: true)) model.AvailableCategories.Add(new SelectListItem() { Text = c.GetCategoryNameWithPrefix(_categoryService), Value = c.Id.ToString() }); //manufacturers model.AvailableManufacturers.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var m in _manufacturerService.GetAllManufacturers(true)) model.AvailableManufacturers.Add(new SelectListItem() { Text = m.Name, Value = m.Id.ToString() }); //add by hz //vendors model.IsVendorManager = (customerVendorId > 0) ? true : false; model.AvailableVendors.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var s in _vendorService.GetAllVendors(0, true)) model.AvailableVendors.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }); //end by hz return View(model); }
public ActionResult GoToSku(ProductListModel model) { string sku = model.GoDirectlyToSku; //try to load a product entity var product = _productService.GetProductBySku(sku); if (product != null) return RedirectToAction("Edit", "Product", new { id = product.Id }); //not found return List(); }