public ActionResult Create() { var model = new ArticleGroupModel(); //parent categories model.ParentGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } }; //locales AddLocales(_languageService, model.Locales); //Stores PrepareStoresMappingModel(model, null, false); model.Published = true; return View(model); }
private IEnumerable <Article> GetArticles() { var vendorAssortment = GetVendorAssortment().ToArray(); var vendorSettings = GetVendorSettings().ToArray(); if (!vendorSettings.Any()) { TraceError("{0}: There are no connector vendor settings defined for the connector or for any of its ancestors!", Context.Name); } else { TraceVerbose("{0}: Loading content for vendor assortment...", Context.Name); var defaultGroup = new ArticleGroupModel { CategoryCode = Constants.DiversCode, CategoryID = Constants.ProductGroup.UnknownID, CategoryName = Constants.DiversName, FamilyCode = Constants.DiversCode, FamilyID = Constants.ProductGroup.UnknownID, FamilyName = Constants.DiversName, SubfamilyCode = Constants.DiversCode, SubfamilyID = Constants.ProductGroup.UnknownID, SubfamilyName = Constants.DiversName }; var articleAttributes = GetArticleAttributes(vendorAssortment, vendorSettings); var articleBarcodes = GetArticleBarcodes(vendorAssortment, vendorSettings); var articleCodes = GetArticleCodes(vendorAssortment, vendorSettings); var articleDescriptions = GetArticleDescriptions(vendorAssortment, vendorSettings); var articleLongDescriptions = articleDescriptions.ToDictionary(articleDescription => articleDescription.ProductID, articleDescription => articleDescription.DescriptionLong); var articleShortDescriptions = articleDescriptions.ToDictionary(articleDescription => articleDescription.ProductID, articleDescription => articleDescription.DescriptionShort); var articleGroups = GetArticleGroups(vendorAssortment, vendorSettings).ToDictionary(articleGroup => articleGroup.ProductID); var articleTariffs = GetArticleTariffs(vendorAssortment); var articles = articleTariffs.Select(articleTariff => new Article { ProductID = articleTariff.ProductID, ArticleID = articleCodes[articleTariff.ProductID].ParentProductID, ArticleCode = articleCodes[articleTariff.ProductID].ArticleCode, Barcode = articleBarcodes.GetValueOrDefault(articleTariff.ProductID, String.Empty), BrandID = articleCodes[articleTariff.ProductID].BrandID, CategoryID = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).CategoryID, CategoryCode = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).CategoryCode, CategoryName = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).CategoryName, Collection = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.Collection), ColorCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.ColorCode, Constants.IgnoreCode), ColorName = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.ColorName, Constants.IgnoreCode), CostPrice = articleTariff.CostPrice, CountryCode = articleTariff.CountryCode, CurrencyCode = articleTariff.CurrencyCode, DescriptionLong = articleLongDescriptions.GetValueOrDefault(articleTariff.ProductID, String.Empty), DescriptionShort = articleShortDescriptions.GetValueOrDefault(articleTariff.ProductID, String.Empty), FamilyID = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).FamilyID, FamilyCode = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).FamilyCode, FamilyName = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).FamilyName, LabelCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.LabelCode, String.Empty), MaterialCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.MaterialCode, String.Empty), OriginCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.OriginCode, String.Empty), Price = articleTariff.UnitPrice, ReferenceCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.ReferenceCode, String.Empty), ReplenishmentMaximum = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.ReplenishmentMaximum, "0").ToInt().GetValueOrDefault(), ReplenishmentMinimum = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.ReplenishmentMinimum, "0").ToInt().GetValueOrDefault(), ShapeCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.ShapeCode, String.Empty), SizeCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.SizeCode, Constants.IgnoreCode), StockType = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.StockType, String.Empty), SubfamilyID = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).SubfamilyID, SubfamilyCode = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).SubfamilyCode, SubfamilyName = articleGroups.GetValueOrDefault(articleTariff.ProductID, defaultGroup).SubfamilyName, SupplierCode = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.SupplierCode), SupplierName = articleAttributes[articleTariff.ProductID].GetValueOrDefault(Constants.Attribute.SupplierName), Tax = articleTariff.TaxRate, VendorID = articleTariff.VendorID, ZoneCode4 = Constants.MissingCode, ZoneCode5 = Constants.MissingCode }); return(articles); } return(null); }
private void PrepareStoresMappingModel(ArticleGroupModel model, ArticleGroup articleGroup, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (articleGroup != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(articleGroup); } else { model.SelectedStoreIds = new int[0]; } } }
protected void UpdateLocales(ArticleGroup articleGroup, ArticleGroupModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(articleGroup, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(articleGroup, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(articleGroup, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(articleGroup, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(articleGroup, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(articleGroup, x => x.SeName, localized.SeName, localized.LanguageId); } }
protected void SaveStoreMappings(ArticleGroup articleGroup, ArticleGroupModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(articleGroup); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) { //new role if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) _storeMappingService.InsertStoreMapping(articleGroup, store.Id); } else { //removed role var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }
public ActionResult Edit(ArticleGroupModel model, bool continueEditing) { var articleGroup = _articleService.GetArticleGroupById(model.Id); if (articleGroup == null || articleGroup.Deleted) //No category found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { int prevPictureId = articleGroup.PictureId; articleGroup = model.ToEntity(articleGroup); articleGroup.UpdatedOnUtc = DateTime.UtcNow; _articleService.UpdateArticleGroup(articleGroup); //search engine name model.SeName = articleGroup.ValidateSeName(model.SeName, articleGroup.Name, true); _urlRecordService.SaveSlug(articleGroup, model.SeName, 0); //locales UpdateLocales(articleGroup, model); _articleService.UpdateArticleGroup(articleGroup); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != articleGroup.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } //update picture seo file name UpdatePictureSeoNames(articleGroup); //Stores SaveStoreMappings(articleGroup, model); //activity log _customerActivityService.InsertActivity("EditArticleGroup", _localizationService.GetResource("ActivityLog.EditArticleGroup"), articleGroup.Name); SuccessNotification(_localizationService.GetResource("Admin.Plugins.ArticleManagement.ArticleGroups.Updated")); return continueEditing ? RedirectToAction("Edit", new{ id = articleGroup.Id }) : RedirectToAction("List" ); } //If we got this far, something failed, redisplay form //parent categories model.ParentGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } }; if (model.ParentGroupId > 0) { var parentCategory = _articleService.GetArticleGroupById(model.ParentGroupId); if (parentCategory != null && !parentCategory.Deleted) model.ParentGroups.Add(new DropDownItem { Text = parentCategory.GetFormattedBreadCrumb(_articleService), Value = parentCategory.Id.ToString() }); else model.ParentGroupId = 0; } //Stores PrepareStoresMappingModel(model, articleGroup, true); return View(model); }
public ActionResult Create(ArticleGroupModel model, bool continueEditing) { if (ModelState.IsValid) { var articleGroup = model.ToEntity(); articleGroup.CreatedOnUtc = DateTime.UtcNow; articleGroup.UpdatedOnUtc = DateTime.UtcNow; _articleService.InsertArticleGroup(articleGroup); //search engine name model.SeName = articleGroup.ValidateSeName(model.SeName, articleGroup.Name, true); _urlRecordService.SaveSlug(articleGroup, model.SeName, 0); //locales UpdateLocales(articleGroup, model); _articleService.UpdateArticleGroup(articleGroup); //update picture seo file name UpdatePictureSeoNames(articleGroup); //Stores SaveStoreMappings(articleGroup, model); //activity log _customerActivityService.InsertActivity("AddNewArticleGroup", _localizationService.GetResource("ActivityLog.AddNewArticleGroup"), articleGroup.Name); SuccessNotification(_localizationService.GetResource("Admin.Plugins.ArticleManagement.ArticleGroups.Added")); return continueEditing ? RedirectToAction("Edit", new { id = articleGroup.Id }) : RedirectToAction("List"); } //parent categories model.ParentGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } }; if (model.ParentGroupId > 0) { var parentArticleGroup = _articleService.GetArticleGroupById(model.ParentGroupId); if (parentArticleGroup != null && !parentArticleGroup.Deleted) model.ParentGroups.Add(new DropDownItem { Text = parentArticleGroup.GetFormattedBreadCrumb(_articleService), Value = parentArticleGroup.Id.ToString() }); else model.ParentGroupId = 0; } //Stores PrepareStoresMappingModel(model, null, true); return View(model); }