private catalogProductCreateEntity LoadData() { using (var entityRepository = ResolverFactory.Resolve <EntityRepository>()) { var relatedIndexedItems = entityRepository.GetIndexedItemsBySourceId(GetIndexModel(), IndexedItem.GetSourceId()); var normalizedValues = relatedIndexedItems .Select(i => new { k = i.GetId(), v = GetNormalizedValuesByDependencies(i) }) .ToDictionary(x => x.k, x => x.v); var attributes = IndexedItem.Properties().Where(p => !HexaFields.Contains(p.Name)) .Select(a => new associativeMultiEntity { key = a.Name, value = normalizedValues.Select(v => { var relatedIndexedItem = relatedIndexedItems.FirstOrDefault(r => r.GetId() == v.Key); if (relatedIndexedItem.HasState(ItemState.Removed)) { return(null); } var normalizedValue = v.Value; if (!normalizedValue.ContainsKey(a.Name)) { return(relatedIndexedItem.Value <string>(a.Name)); } return(normalizedValue[a.Name]); }) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToArray() }) .ToArray(); var result = new catalogProductCreateEntity { additional_attributes = new catalogProductAdditionalAttributesEntity { multi_data = attributes } }; return(result); } }
private catalogProductCreateEntity LoadEntity() { var normalizedValues = GetNormalizedValuesByDependencies(); var attributes = IndexedItem.Properties().Where(p => !HexaFields.Contains(p.Name)) .Select(a => new associativeEntity { key = a.Name, value = normalizedValues.ContainsKey(a.Name) ? normalizedValues[a.Name] : IndexedItem.Value <string>(a.Name) }) .ToArray(); var result = new catalogProductCreateEntity { additional_attributes = new catalogProductAdditionalAttributesEntity { single_data = attributes }, }; return(result); }
public override PushState Create(out string destinationId) { var pushState = PushState.Success; soap.SetOptions(Adapter.Options); var indexedModel = GetIndexModel(); var additionalFields = IndexedItem.Properties().Where(p => !HexaFields.Contains(p.Name) && !ProductFields.Contains(p.Name)).Select(p => p.Name); var websiteIds = Regex.Split(Options.FirstOrDefault(o => o.Name == "website_ids").Value, "[,;|]", RegexOptions.Multiline | RegexOptions.IgnoreCase); var storeIds = Regex.Split(Options.FirstOrDefault(o => o.Name == "store_ids").Value, "[,;|]", RegexOptions.Multiline | RegexOptions.IgnoreCase); var normalizedValues = GetNormalizedValuesByDependencies(); try { var additionalAttrs = additionalFields.Select(f => new associativeEntity { key = f, value = normalizedValues.ContainsKey(f) ? normalizedValues[f] : IndexedItem.Value <string>(f) }); var attributes = new catalogProductAdditionalAttributesEntity { single_data = additionalAttrs.ToArray() }; var data = new catalogProductCreateEntity { website_ids = websiteIds, additional_attributes = attributes, status = "2", visibility = "4", stock_data = new catalogInventoryStockItemUpdateEntity() { qty = "0", is_in_stock = 1, } }; soap.Begin(); var client = soap.GetClient(); destinationId = client .catalogProductCreate(soap.GetSession(), normalizedValues.ContainsKey("type") ? normalizedValues["type"] : IndexedItem.Value <string>("type"), normalizedValues.ContainsKey("attribute_set_id") ? normalizedValues["attribute_set_id"] : IndexedItem.Value <string>("attribute_set_id"), IndexedItem.Value <string>("sku"), data, "0").ToString(); foreach (var storeId in storeIds) { client.catalogProductMultiUpdateAsync( soap.GetSession(), new string[] { destinationId }, new catalogProductCreateEntity[] { new catalogProductCreateEntity { website_ids = websiteIds, status = "2" // Creating product always set status to false. itemModel.removed == DIndex.ConstYes ? "2" : "1" } }, storeId, "id"); } return(pushState); } finally { soap.End(); } }