protected virtual IDictionary <string, int> GetAttributeIdByAliasMappings() { return(_cacheManager.Get(ALL_ATTRIBUTE_ID_BY_ALIAS_KEY, () => { var result = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); var optionIdMappings = new Dictionary <int, int>(); IPagedList <SpecificationAttribute> attributes = null; var attributeId = 0; var pageIndex = 0; var query = _specificationAttributeService.GetSpecificationAttributes() .Expand(x => x.SpecificationAttributeOptions) .OrderBy(x => x.Id); do { attributes = new PagedList <SpecificationAttribute>(query, pageIndex++, 500); foreach (var attribute in attributes) { if (attribute.Alias.HasValue()) { result[CreateKey("attr", 0, attribute.Alias)] = attribute.Id; } foreach (var option in attribute.SpecificationAttributeOptions) { optionIdMappings[option.Id] = option.SpecificationAttributeId; if (option.Alias.HasValue()) { result[CreateOptionKey("attr.option", 0, attribute.Id, option.Alias)] = option.Id; } } } }while (attributes.HasNextPage); attributes.Clear(); CachedLocalizedAlias("SpecificationAttribute", x => result[CreateKey("attr", x.LanguageId, x.LocaleValue)] = x.EntityId); CachedLocalizedAlias("SpecificationAttributeOption", x => { if (optionIdMappings.TryGetValue(x.EntityId, out attributeId)) { result[CreateOptionKey("attr.option", x.LanguageId, attributeId, x.LocaleValue)] = x.EntityId; } }); return result; })); }
public ActionResult List(GridCommand command) { var gridModel = new GridModel <SpecificationAttributeModel>(); if (_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { var data = _specificationAttributeService.GetSpecificationAttributes() .Expand(x => x.SpecificationAttributeOptions) .ForCommand(command) .Select(x => { var model = x.ToModel(); model.OptionCount = x.SpecificationAttributeOptions.Count; return(model); }) .ToList(); gridModel.Data = data.PagedForCommand(command); gridModel.Total = data.Count; } else { gridModel.Data = Enumerable.Empty <SpecificationAttributeModel>(); NotifyAccessDenied(); } return(new JsonResult { Data = gridModel }); }
public ActionResult List() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } var specificationAttributes = _specificationAttributeService.GetSpecificationAttributes(); var gridModel = new GridModel <SpecificationAttributeModel> { Data = specificationAttributes.Select(x => x.ToModel()), Total = specificationAttributes.Count() }; return(View(gridModel)); }
public ActionResult List(GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var optionsText = _localizationService.GetResource("Admin.Catalog.Attributes.SpecificationAttributes.Options"); var data = _specificationAttributeService.GetSpecificationAttributes() .Expand(x => x.SpecificationAttributeOptions) .ForCommand(command) .Select(x => { var model = x.ToModel(); model.OptionCount = x.SpecificationAttributeOptions.Count; return(model); }) .ToList(); var gridModel = new GridModel <SpecificationAttributeModel> { Data = data.PagedForCommand(command), Total = data.Count }; return(new JsonResult { Data = gridModel }); }
/// <summary> /// Install plugin /// </summary> public override void Install() { var artistAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Artist").FirstOrDefault(); if (artistAttr == null) { artistAttr = new Core.Domain.Catalog.SpecificationAttribute(); artistAttr.Name = "Artist"; _specificationAttributeService.InsertSpecificationAttribute(artistAttr); } var DefaultEnvelopeColorAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "DefaultEnvelopeColor").FirstOrDefault(); if (DefaultEnvelopeColorAttr == null) { DefaultEnvelopeColorAttr = new Core.Domain.Catalog.SpecificationAttribute(); DefaultEnvelopeColorAttr.Name = "DefaultEnvelopeColor"; _specificationAttributeService.InsertSpecificationAttribute(DefaultEnvelopeColorAttr); } var OrientationAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Orientation").FirstOrDefault(); if (OrientationAttr == null) { OrientationAttr = new Core.Domain.Catalog.SpecificationAttribute(); OrientationAttr.Name = "Orientation"; var _specificationOptionsVertical = new Core.Domain.Catalog.SpecificationAttributeOption(); _specificationOptionsVertical.Name = "Vertical"; OrientationAttr.SpecificationAttributeOptions.Add(_specificationOptionsVertical); var _specificationOptionsHorizontal = new Core.Domain.Catalog.SpecificationAttributeOption(); _specificationOptionsHorizontal.Name = "Horizontal"; OrientationAttr.SpecificationAttributeOptions.Add(_specificationOptionsHorizontal); _specificationAttributeService.InsertSpecificationAttribute(OrientationAttr); } this.AddOrUpdatePluginLocaleResource("Plugin.ProductArtist.ArtistName", "Artist"); this.AddOrUpdatePluginLocaleResource("Plugin.ProductArtist.ArtistName.Hint", "Artist"); this.AddOrUpdatePluginLocaleResource("Plugin.Product.Atist", "Artist"); this.AddOrUpdatePluginLocaleResource("Plugin.Artist.Saved", "Artist Saved"); this.AddOrUpdatePluginLocaleResource("artistname.by", "by"); this.AddOrUpdatePluginLocaleResource("Product.Category", "Categories"); base.Install(); }
public ActionResult ProductTabPost(int id, string ArtistName) { var product = _productService.GetProductById(id); if (product != null) { // _genericAttributeService.SaveAttribute<string>(product, ProductArtistAttributeNames.ArtistName, ArtistName, _storeContext.CurrentStore.Id); var artistAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Artist").FirstOrDefault(); if (artistAttr != null) { var value = artistAttr.SpecificationAttributeOptions.Where(x => x.Name == ArtistName).FirstOrDefault(); if (value != null) { ProductSpecificationAttribute psA = new ProductSpecificationAttribute(); psA.SpecificationAttributeOption = value; psA.ProductId = product.Id; psA.AllowFiltering = true; psA.AttributeType = SpecificationAttributeType.Option; psA.ShowOnProductPage = true; _specificationAttributeService.InsertProductSpecificationAttribute(psA); } else { value = new SpecificationAttributeOption { Name = ArtistName, SpecificationAttributeId = artistAttr.Id }; _specificationAttributeService.InsertSpecificationAttributeOption(value); ProductSpecificationAttribute psA = new ProductSpecificationAttribute(); psA.SpecificationAttributeOption = value; psA.ProductId = product.Id; psA.AllowFiltering = true; psA.AttributeType = SpecificationAttributeType.Option; psA.ShowOnProductPage = true; _specificationAttributeService.InsertProductSpecificationAttribute(psA); } } } return(Content(ArtistName)); }
public async Task<IActionResult> ConditionProductSpecification(string customerActionId, string conditionId) { var customerActions = await _customerActionService.GetCustomerActionById(customerActionId); var condition = customerActions.Conditions.FirstOrDefault(x => x.Id == conditionId); var specs = await _specificationAttributeService.GetSpecificationAttributes(); var gridModel = new DataSourceResult { Data = condition != null ? condition.ProductSpecifications .Select(z => new { Id = z.Id, SpecificationId = z.ProductSpecyficationId, SpecificationName = specs.FirstOrDefault(x=>x.Id == z.ProductSpecyficationId)?.Name, SpecificationValueName = !String.IsNullOrEmpty(z.ProductSpecyficationValueId) ? specs.FirstOrDefault(x => x.Id == z.ProductSpecyficationId).SpecificationAttributeOptions.FirstOrDefault(x => x.Id == z.ProductSpecyficationValueId).Name : "Undefined" }) : null, Total = customerActions.Conditions.Where(x => x.Id == conditionId).Count() }; return Json(gridModel); }
public IHttpActionResult GetSpecificationAttributes() { return(RunInSafe(() => { var data = _specificationAttributeService.GetSpecificationAttributes(); tebResponse.Data = data.Result; tebResponse.IsSuccess = true; return Ok(tebResponse); })); }
private void UpdateProductSpecificationOption(ImportEntity importEntity) { var productFromBase = _productService.GetProductBySku(importEntity.ProductSku); var allSpecificationOptions = _specificationAttributeService.GetSpecificationAttributes(); var specificationMap = allSpecificationOptions.ToDictionary(i => i.Name, i => i); //если айди аттрибута из импорта нету в списке из связей в базе, то добавляем foreach (var productSpecificationAttribute in importEntity.ProductSpecifications) { if (!String.IsNullOrWhiteSpace(productSpecificationAttribute.Value)) { var importProductSpecification = _configImportCategoryEntity.ProductSpecifications.FirstOrDefault( x => x.RusName.Equals(productSpecificationAttribute.Name)); var allowFilter = importProductSpecification != null && importProductSpecification.FilterBy; //пропишем айди в для specificationOptions из базы GetIdForSpecificationOption(specificationMap, productSpecificationAttribute); var productSpecifications = _productService.GetProductBySku(importEntity.ProductSku).ProductSpecificationAttributes; var productSpecificationAttributeOption = productSpecifications.FirstOrDefault( x => x.SpecificationAttributeOption.SpecificationAttributeId.Equals(productSpecificationAttribute.SpecificationId)); if (productSpecificationAttributeOption == null) { ProductSpecificationAttributeOptionMapping(productFromBase, productSpecificationAttribute, allowFilter); } else { _specificationAttributeService.DeleteProductSpecificationAttribute( productSpecificationAttributeOption); ProductSpecificationAttributeOptionMapping(productFromBase, productSpecificationAttribute, allowFilter); } } } }
public IActionResult GetSpecificationAttributesCount(SpecifcationAttributesCountParametersModel parameters) { var specificationAttributesCount = _specificationAttributeService.GetSpecificationAttributes().Count(); var specificationAttributesCountRootObject = new SpecificationAttributesCountRootObject() { Count = specificationAttributesCount }; return(Ok(specificationAttributesCountRootObject)); }
public async Task <IActionResult> List(DataSourceRequest command) { var specificationAttributes = await _specificationAttributeService .GetSpecificationAttributes(command.Page - 1, command.PageSize); var gridModel = new DataSourceResult { Data = specificationAttributes.Select(x => x.ToModel()), Total = specificationAttributes.TotalCount }; return(Json(gridModel)); }
public ActionResult List(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } var specificationAttributes = _specificationAttributeService .GetSpecificationAttributes(command.Page - 1, command.PageSize); var gridModel = new DataSourceResult { Data = specificationAttributes.Select(x => x.ToModel()), Total = specificationAttributes.TotalCount }; return(Json(gridModel)); }
public ActionResult List(GridCommand command) { var gridModel = new GridModel <SpecificationAttributeModel>(); var data = _specificationAttributeService.GetSpecificationAttributes() .ForCommand(command) .Select(x => x.ToModel()) .ToList(); gridModel.Data = data.PagedForCommand(command); gridModel.Total = data.Count; return(new JsonResult { Data = gridModel }); }
public HttpResponseMessage Get(HttpRequestMessage request, int pageIndex = 0, int pageSize = int.MaxValue) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No item(s) found"); var specificationAttributes = _specificationAttributeService.GetSpecificationAttributes(pageIndex, pageSize); if (specificationAttributes != null) { var gridModel = new DataSourceResult { Data = specificationAttributes.Select(x => x.ToModel()), Total = specificationAttributes.TotalCount }; response = request.CreateResponse <DataSourceResult>(HttpStatusCode.OK, gridModel); } return response; })); }
/// <summary> /// Prepare paged specification attribute list model /// </summary> /// <param name="searchModel">Specification attribute search model</param> /// <returns>Specification attribute list model</returns> public virtual SpecificationAttributeListModel PrepareSpecificationAttributeListModel(SpecificationAttributeSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get specification attributes var specificationAttributes = _specificationAttributeService .GetSpecificationAttributes(searchModel.Page - 1, searchModel.PageSize); //prepare list model var model = new SpecificationAttributeListModel().PrepareToGrid(searchModel, specificationAttributes, () => { //fill in model values from the entity return(specificationAttributes.Select(attribute => attribute.ToModel <SpecificationAttributeModel>())); }); return(model); }
/// <summary> /// Prepare paged specification attribute list model /// </summary> /// <param name="searchModel">Specification attribute search model</param> /// <returns>Specification attribute list model</returns> public virtual SpecificationAttributeListModel PrepareSpecificationAttributeListModel(SpecificationAttributeSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get specification attributes var specificationAttributes = _specificationAttributeService .GetSpecificationAttributes(searchModel.Page - 1, searchModel.PageSize); //prepare list model var model = new SpecificationAttributeListModel { //fill in model values from the entity Data = specificationAttributes.Select(attribute => attribute.ToModel()), Total = specificationAttributes.TotalCount }; return(model); }
public ActionResult List(GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var data = _specificationAttributeService.GetSpecificationAttributes() .ForCommand(command) .Select(x => x.ToModel()) .ToList(); var gridModel = new GridModel <SpecificationAttributeModel> { Data = data.PagedForCommand(command), Total = data.Count }; return(new JsonResult { Data = gridModel }); }
public ActionResult List(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } var specificationAttributes = _specificationAttributeService .GetSpecificationAttributes(command.Page - 1, command.PageSize); var gridModel = new DataSourceResult { Data = specificationAttributes.Select(x => x.ToModel()), Total = specificationAttributes.TotalCount }; var AllCategorySpecificationAtrributes = _categorySpecificationAtrributeService.LoadAllCategorySpecificationAtrribute(); List <SpecificationAttributeModel> collection = new List <SpecificationAttributeModel>(); foreach (SpecificationAttributeModel item in gridModel.Data) { var e = AllCategorySpecificationAtrributes.ToList().Find(s => s.SpecificationAttributeId == item.Id); if (e != null) { item.SearchCategoryId = e.CategoryId; item.AllowFiltering = e.AllowFiltering; var categories = _categoryService.GetCategoryById(e.CategoryId); item.CategoryName = categories.Name; } collection.Add(item); } gridModel.Data = collection; // //foreach (var c in categories) // model.AvailableCategories.Add(new SelectListItem() { Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString() }); return(Json(gridModel)); }
/// <summary> /// Install plugin /// </summary> public override void Install() { var artistAttr = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Artist").FirstOrDefault(); if (artistAttr == null) { artistAttr = new Core.Domain.Catalog.SpecificationAttribute(); artistAttr.Name = "Artist"; _specificationAttributeService.InsertSpecificationAttribute(artistAttr); } var Treatment = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "Treatment").FirstOrDefault(); if (Treatment == null) { Treatment = new Core.Domain.Catalog.SpecificationAttribute(); Treatment.Name = "Treatment"; var _specificationOptionsTreatmentImage = new Core.Domain.Catalog.SpecificationAttributeOption(); _specificationOptionsTreatmentImage.Name = "TreatmentImage"; Treatment.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentImage); var _specificationOptionsTreatmentFill = new Core.Domain.Catalog.SpecificationAttributeOption(); _specificationOptionsTreatmentFill.Name = "TreatmentFill"; Treatment.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentFill); _specificationAttributeService.InsertSpecificationAttribute(Treatment); } var TreatmentImage = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentImage").FirstOrDefault(); if (TreatmentImage == null) { TreatmentImage = new Core.Domain.Catalog.SpecificationAttribute(); TreatmentImage.Name = "TreatmentImage"; _specificationAttributeService.InsertSpecificationAttribute(TreatmentImage); } var TreatmentFill = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentFill").FirstOrDefault(); if (TreatmentFill == null) { TreatmentFill = new Core.Domain.Catalog.SpecificationAttribute(); TreatmentFill.Name = "TreatmentFill"; var _specificationOptionsTreatmentFillColor = new Core.Domain.Catalog.SpecificationAttributeOption(); _specificationOptionsTreatmentFillColor.Name = "TreatmentFillColor"; TreatmentFill.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentFillColor); var _specificationOptionsTreatmentFillPattern = new Core.Domain.Catalog.SpecificationAttributeOption(); _specificationOptionsTreatmentFillPattern.Name = "TreatmentFillPattern"; TreatmentFill.SpecificationAttributeOptions.Add(_specificationOptionsTreatmentFillPattern); _specificationAttributeService.InsertSpecificationAttribute(TreatmentFill); } var TreatmentFillColor = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentFillColor").FirstOrDefault(); if (TreatmentFillColor == null) { TreatmentFillColor = new Core.Domain.Catalog.SpecificationAttribute(); TreatmentFillColor.Name = "TreatmentFillColor"; _specificationAttributeService.InsertSpecificationAttribute(TreatmentFillColor); } var TreatmentFillPattern = _specificationAttributeService.GetSpecificationAttributes().Where(x => x.Name == "TreatmentFillPattern").FirstOrDefault(); if (TreatmentFillPattern == null) { TreatmentFillPattern = new Core.Domain.Catalog.SpecificationAttribute(); TreatmentFillPattern.Name = "TreatmentFillPattern"; _specificationAttributeService.InsertSpecificationAttribute(TreatmentFillPattern); } this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.ArtistName", "Artist"); this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.ArtistName.Hint", "Artist"); this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.Artist", "Artist"); this.AddOrUpdatePluginLocaleResource("Plugin.Prodcuts.SpecificationAttributes.Artist.Saved", "Artist Saved"); this.AddOrUpdatePluginLocaleResource("artistname.by", "by"); this.AddOrUpdatePluginLocaleResource("Product.Category", "Categories"); base.Install(); }
private void InstallAttributes(CcSettings settings) { var attributes = _productAttributeService.GetAllProductAttributes(); var specificationAttributes = _specificationAttributeService.GetSpecificationAttributes(); var ccIdAttribute = attributes.FirstOrDefault(x => x.Name == "CcId"); if (ccIdAttribute == null) { ccIdAttribute = new ProductAttribute() { Name = "CcId" }; _productAttributeService.InsertProductAttribute(ccIdAttribute); } var editorDefinitionSpecificationAttribute = specificationAttributes.FirstOrDefault(x => x.Name == "CC Editor"); if (editorDefinitionSpecificationAttribute == null) { editorDefinitionSpecificationAttribute = new SpecificationAttribute { Name = "CC Editor", DisplayOrder = 100 }; _specificationAttributeService.InsertSpecificationAttribute(editorDefinitionSpecificationAttribute); } var editorDefinitionSpecificationOption = editorDefinitionSpecificationAttribute.SpecificationAttributeOptions.FirstOrDefault(x => x.Name == "CC Editor"); if (editorDefinitionSpecificationOption == null) { editorDefinitionSpecificationOption = new SpecificationAttributeOption { DisplayOrder = 0, Name = "CC Editor", SpecificationAttributeId = editorDefinitionSpecificationAttribute.Id }; _specificationAttributeService.InsertSpecificationAttributeOption(editorDefinitionSpecificationOption); } var editorConfigurationSpecificationAttribute = specificationAttributes.FirstOrDefault(x => x.Name == "CC EditorConfig"); if (editorConfigurationSpecificationAttribute == null) { editorConfigurationSpecificationAttribute = new SpecificationAttribute { Name = "CC EditorConfig", DisplayOrder = 100 }; _specificationAttributeService.InsertSpecificationAttribute(editorConfigurationSpecificationAttribute); } var editorConfigurationSpecificationOption = editorDefinitionSpecificationAttribute.SpecificationAttributeOptions.FirstOrDefault(x => x.Name == "CC EditorConfig"); if (editorConfigurationSpecificationOption == null) { editorConfigurationSpecificationOption = new SpecificationAttributeOption { DisplayOrder = 0, Name = "CC EditorConfig", SpecificationAttributeId = editorConfigurationSpecificationAttribute.Id }; _specificationAttributeService.InsertSpecificationAttributeOption(editorConfigurationSpecificationOption); } // add to settings settings.CcIdAttributeId = ccIdAttribute.Id; settings.EditorDefinitionSpecificationAttributeId = editorDefinitionSpecificationAttribute.Id; settings.EditorDefinitionSpecificationOptionId = editorDefinitionSpecificationOption.Id; settings.EditorConfigurationSpecificationAttributeId = editorConfigurationSpecificationAttribute.Id; settings.EditorConfigurationSpecificationOptionId = editorConfigurationSpecificationOption.Id; }
public IActionResult ProductSpecification() { var customerAttr = _specificationAttributeService.GetSpecificationAttributes().Select(x => new { Id = x.Id, Name = x.Name }); return(Json(customerAttr)); }
internal static List <SpecificationAttribute> Import(КоммерческаяИнформация source, ISpecificationAttributeService specificationAttributeService, string mappingsFile, out Dictionary <string, int> outMappings, string logFile) { logFile.Log("Начало импорта свойств"); var stats = new[] { 0, 0, 0, 0 }; // attribute: key = 1c id, value = nopcommerce id // attribute value: key = <1c attribute id>.<1c value id>, value = nopcommerce id var mappings = File.Exists(mappingsFile) ? JsonConvert.DeserializeObject <Dictionary <string, int> >(File.ReadAllText(mappingsFile)) : new Dictionary <string, int>();; var attributes = specificationAttributeService.GetSpecificationAttributes().ToList(); foreach (var attr in source.Классификатор.Свойства) { // ищем соответствие только по маппингу // потому что может быть несколько атрибутов с одинаковым названием var attribute = mappings.ContainsKey(attr.Ид) ? attributes.FirstOrDefault(a => a.Id == mappings[attr.Ид]) : null; if (attribute != null) { // для существующего только добавляем новые значения if (attr.ТипЗначений == AttrTypeDictionary) { foreach (var attrOption in attr.ВариантыЗначений) { var key = $"{attr.Ид}.{attrOption.ИдЗначения}"; var option = mappings.ContainsKey(key) ? attribute.SpecificationAttributeOptions.FirstOrDefault(o => o.Id == mappings[key]) : null; if (option == null) { // ищем по имени option = attribute.SpecificationAttributeOptions.FirstOrDefault(o => o.Name == attrOption.Значение); if (option == null) { // добавляем новое значение option = new Core.Domain.Catalog.SpecificationAttributeOption { SpecificationAttributeId = attribute.Id, Name = attrOption.Значение }; specificationAttributeService.InsertSpecificationAttributeOption(option); attribute.SpecificationAttributeOptions.Add(option); //logFile.Log($"В существующий атрибут {attribute.Name} ({attribute.Id}) добавлено значение {option.Name}"); stats[0]++; } else { // мапим существующее значение //logFile.Log($"В существующем атрибуте {attribute.Name} ({attribute.Id}) добавлено сопоставление для значения {option.Name}"); stats[1]++; } mappings[key] = option.Id; } } } continue; } // new attribute attribute = new Core.Domain.Catalog.SpecificationAttribute { Name = attr.Наименование }; specificationAttributeService.InsertSpecificationAttribute(attribute); attributes.Add(attribute); mappings[attr.Ид] = attribute.Id; //logFile.Log($"Новый атрибут {attribute.Name} ({attribute.Id})"); stats[2]++; if (attr.ТипЗначений == AttrTypeDictionary) { foreach (var attrOption in attr.ВариантыЗначений) { var key = $"{attr.Ид}.{attrOption.ИдЗначения}"; var option = new Core.Domain.Catalog.SpecificationAttributeOption { SpecificationAttributeId = attribute.Id, Name = attrOption.Значение }; specificationAttributeService.InsertSpecificationAttributeOption(option); attribute.SpecificationAttributeOptions.Add(option); mappings[key] = option.Id; //logFile.Log($"В новый атрибут {attribute.Name} ({attribute.Id}) добавлено значение {option.Name}"); stats[3]++; } } else { var key = $"{attr.Ид}."; var option = new Core.Domain.Catalog.SpecificationAttributeOption { SpecificationAttributeId = attribute.Id, Name = string.Empty }; specificationAttributeService.InsertSpecificationAttributeOption(option); attribute.SpecificationAttributeOptions.Add(option); mappings[key] = option.Id; } } File.WriteAllText(mappingsFile, JsonConvert.SerializeObject(mappings, Formatting.Indented), Encoding.UTF8); logFile.Log($"Импорт свойств завершен. Привязано: {stats[0]} атрибутов и {stats[1]} значений. Добавлено: {stats[2]} атрибутов и {stats[3]} значений."); outMappings = mappings; return(attributes); }
/// <summary> /// // Возвращает спецификаций магазина, дополненные из парсера /// </summary> public IList <SpecificationAttribute> GetSumOfYandexSpecsAndShopSpecs(IEnumerable <int> categoryIdList) { // Все спецификации парсера для выбранных категорий товаров var yandexMarketSpecList = new List <YandexMarketSpecRecord>(); foreach (var currentCategoryId in categoryIdList) { var yaSpecsForCurCategory = _yandexMarketSpecService.GetByCategory(currentCategoryId); yandexMarketSpecList.AddRange(yaSpecsForCurCategory); } // Все спецификации магазина var shopSpecList = new List <SpecificationAttribute>(); foreach (var specificationAttribute in _shopSpecService.GetSpecificationAttributes()) { shopSpecList.Add(specificationAttribute.Clone()); } try { // Объединяем спецификации в единый список магазина foreach (var curYaSpec in yandexMarketSpecList) { // Find Spec var existedShopSpec = shopSpecList.SingleOrDefault(x => x.Name == curYaSpec.Key); if (existedShopSpec == null) { existedShopSpec = new SpecificationAttribute() { Name = curYaSpec.Key }; shopSpecList.Add(existedShopSpec); } // Find Spec option var existedShopSpecOpt = existedShopSpec.SpecificationAttributeOptions.SingleOrDefault(x => x.Name == curYaSpec.Value); if (existedShopSpecOpt == null) { // string curYaSpecValue = curYaSpec.Value; //if (curYaSpecValue.Length >= 440) //curYaSpecValue = curYaSpecValue.Substring(0, 430); existedShopSpecOpt = new SpecificationAttributeOption() { Name = curYaSpec.Value, DisplayOrder = 777, }; existedShopSpec.SpecificationAttributeOptions.Add(existedShopSpecOpt); } } } catch (Exception) { throw; } return(shopSpecList); }
public JsonResult SaveCcAttribute(int productId, string attributeName, string attributeValue) { try { var specificationAttributes = _specificationAttributeService.GetProductSpecificationAttributes(productId); var prodSpecAttr = specificationAttributes.FirstOrDefault( x => x.SpecificationAttributeOption.SpecificationAttribute.Name == attributeName); if (prodSpecAttr == null) { var allSpecAttrs = _specificationAttributeService.GetSpecificationAttributes(); var currSpecAttr = allSpecAttrs.FirstOrDefault(x => x.Name == attributeName); if (currSpecAttr == null) { currSpecAttr = new SpecificationAttribute(); currSpecAttr.Name = attributeName; currSpecAttr.DisplayOrder = 0; _specificationAttributeService.InsertSpecificationAttribute(currSpecAttr); var newAttrOption = new SpecificationAttributeOption(); newAttrOption.SpecificationAttribute = currSpecAttr; newAttrOption.Name = attributeName; newAttrOption.DisplayOrder = 0; _specificationAttributeService.InsertSpecificationAttributeOption(newAttrOption); } prodSpecAttr = new ProductSpecificationAttribute { AttributeType = SpecificationAttributeType.CustomText, ProductId = productId, SpecificationAttributeOptionId = currSpecAttr.SpecificationAttributeOptions.First().Id, DisplayOrder = 0, ShowOnProductPage = false, AllowFiltering = false, CustomValue = attributeValue, }; _specificationAttributeService.InsertProductSpecificationAttribute(prodSpecAttr); } else { prodSpecAttr.CustomValue = attributeValue; prodSpecAttr.ShowOnProductPage = false; _specificationAttributeService.UpdateProductSpecificationAttribute(prodSpecAttr); } var productAttributeMappings = _productAttributeService.GetProductAttributeMappingsByProductId(productId); foreach (var attrId in _ccService.GetCcAttrIds()) { if (productAttributeMappings.All(map => map.ProductAttributeId != attrId)) { _productAttributeService.InsertProductAttributeMapping(new ProductAttributeMapping { AttributeControlType = AttributeControlType.TextBox, DefaultValue = "", DisplayOrder = 100, ProductId = productId, ProductAttributeId = attrId }); } } return(Json(new { status = "success" })); } catch (Exception ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ""; return(Json(new { status = "error", message = ex.Message + " " + message })); } }