public async Task <IActionResult> ProductAddPopup(CollectionModel.AddCollectionProductModel model) { if (ModelState.IsValid) { if (model.SelectedProductIds != null) { await _collectionViewModelService.InsertCollectionProductModel(model); } ViewBag.RefreshPage = true; } else { Error(ModelState); } return(View(model)); }
public virtual async Task <CollectionModel.AddCollectionProductModel> PrepareAddCollectionProductModel(string storeId) { var model = new CollectionModel.AddCollectionProductModel(); //collections model.AvailableCollections.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " }); foreach (var m in await _collectionService.GetAllCollections(showHidden: true)) { model.AvailableCollections.Add(new SelectListItem { Text = m.Name, Value = m.Id.ToString() }); } //stores model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " }); foreach (var s in (await _storeService.GetAllStores()).Where(x => x.Id == storeId || string.IsNullOrWhiteSpace(storeId))) { model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id.ToString() }); } //vendors model.AvailableVendors.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " }); foreach (var v in await _vendorService.GetAllVendors(showHidden: true)) { model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id.ToString() }); } //product types model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(_translationService, _workContext, false).ToList(); model.AvailableProductTypes.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "0" }); return(model); }
public virtual async Task InsertCollectionProductModel(CollectionModel.AddCollectionProductModel model) { foreach (string id in model.SelectedProductIds) { var product = await _productService.GetProductById(id); if (product != null) { var existingProductcollections = product.ProductCollections; if (product.ProductCollections.Where(x => x.CollectionId == model.CollectionId).Count() == 0) { await _productCollectionService.InsertProductCollection( new ProductCollection { CollectionId = model.CollectionId, IsFeaturedProduct = false, DisplayOrder = 1, }, product.Id); } } } }
public async Task <IActionResult> ProductAddPopupList(DataSourceRequest command, CollectionModel.AddCollectionProductModel model) { if (await _groupService.IsStaff(_workContext.CurrentCustomer)) { model.SearchStoreId = _workContext.CurrentCustomer.StaffStoreId; } var products = await _collectionViewModelService.PrepareProductModel(model, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = products.products.ToList(), Total = products.totalCount }; return(Json(gridModel)); }
public virtual async Task <(IList <ProductModel> products, int totalCount)> PrepareProductModel(CollectionModel.AddCollectionProductModel model, int pageIndex, int pageSize) { var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId, model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId, model.SearchProductName, pageIndex, pageSize); return(products.Select(x => x.ToModel(_dateTimeService)).ToList(), products.TotalCount); }