Exemple #1
0
        private void AddItemToSkusAssociations(LinkType linkType,
                                               StructureEntity structureEntity,
                                               string skuId)
        {
            string associationName = _epiMappingHelper.GetAssociationName(structureEntity);

            Entity source = _entityService.GetEntity(structureEntity.ParentId, LoadLevel.DataOnly);

            List <string> skuCodes = _catalogElementFactory.SkuItemIds(source);

            for (var i = 0; i < skuCodes.Count; i++)
            {
                skuCodes[i] = _catalogCodeGenerator.GetPrefixedCode(skuCodes[i]);
            }

            foreach (string skuCode in skuCodes)
            {
                string associationKey = _catalogCodeGenerator.GetAssociationKey(skuCode, structureEntity.ParentId.ToString(), associationName);
                if (_epiElementContainer.HasAssociation(associationKey))
                {
                    continue;
                }

                XElement existingCatalogAssociationElement = _epiElementContainer.Associations.FirstOrDefault(
                    x => x.Element("Name")?.Value == associationName &&
                    x.Element("EntryCode")?.Value == skuCode);
                ;

                var associationElement = new XElement("Association",
                                                      new XElement("EntryCode", skuId),
                                                      new XElement("SortOrder", structureEntity.SortOrder),
                                                      new XElement("Type", linkType.Id));

                if (existingCatalogAssociationElement != null)
                {
                    if (existingCatalogAssociationElement.Descendants().Any(e => e.Name.LocalName == "EntryCode" && e.Value == skuId))
                    {
                        continue;
                    }

                    existingCatalogAssociationElement.Add(associationElement);
                    _epiElementContainer.AddAssociationKey(associationKey);
                }
                else
                {
                    var catalogAssociation = new XElement("CatalogAssociation",
                                                          new XElement("Name", associationName),
                                                          new XElement("Description", linkType.Id),
                                                          new XElement("SortOrder", structureEntity.SortOrder),
                                                          new XElement("EntryCode", skuCode),
                                                          associationElement);

                    _epiElementContainer.AddAssociation(catalogAssociation, associationKey);
                }
            }
        }
        private void AddRelations(LinkType linkType,
                                  StructureEntity structureEntity,
                                  Entity entity)
        {
            List <string> skus = new List <string> {
                _catalogCodeGenerator.GetEpiserverCode(entity.Id)
            };

            var parentId = structureEntity.EntityId;

            if (structureEntity.IsItem() && _config.ItemsToSkus)
            {
                skus = _catalogElementFactory.SkuItemIds(entity);
                for (var i = 0; i < skus.Count; i++)
                {
                    skus[i] = _catalogCodeGenerator.GetPrefixedCode(skus[i]);
                }

                if (_config.UseThreeLevelsInCommerce)
                {
                    skus.Add(_catalogCodeGenerator.GetEpiserverCode(parentId));
                }
            }

            foreach (var skuId in skus)
            {
                if (_epiMappingHelper.IsRelation(linkType))
                {
                    AddNodeEntryRelationElement(linkType, structureEntity, skuId);
                    AddEntryRelationElement(structureEntity, skuId, linkType);
                }
                else
                {
                    if (_config.ForceIncludeLinkedContent)
                    {
                        AddMissingParentRelation(structureEntity, skuId);
                    }
                    AddAssociationElements(linkType, structureEntity, skuId);
                }
            }
        }
Exemple #3
0
        public XElement CreateResourceElement(Entity resource, string action)
        {
            IntegrationLogger.Write(LogLevel.Debug, $"Creating resource element for resource ID {resource.Id} resource entities found.");

            var parents = new Dictionary <string, int?>();

            List <StructureEntity> allResourceLocations = _entityService.GetAllResourceLocations(resource.Id);

            var links = new List <Link>();

            foreach (Link inboundLink in resource.InboundLinks)
            {
                if (allResourceLocations.Any(i => i.ParentId == inboundLink.Source.Id))
                {
                    links.Add(inboundLink);
                }
            }

            foreach (Link link in links)
            {
                Entity linkedEntity = link.Source;

                var ids = new List <string> {
                    _catalogCodeGenerator.GetEpiserverCode(linkedEntity)
                };

                if (_config.UseThreeLevelsInCommerce)
                {
                    ids.Add(_catalogCodeGenerator.GetEpiserverCode(linkedEntity));
                }

                if (_config.ItemsToSkus && linkedEntity.EntityType.Id == "Item")
                {
                    List <string> skuIds = _catalogElementFactory.SkuItemIds(linkedEntity);
                    foreach (string skuId in skuIds)
                    {
                        string prefixedSkuId = _catalogCodeGenerator.GetPrefixedCode(skuId);
                        ids.Add(prefixedSkuId);
                    }
                }

                foreach (string id in ids)
                {
                    if (!parents.ContainsKey(id))
                    {
                        parents.Add(id, linkedEntity.MainPictureId);
                    }
                }
            }

            string resourceId = _catalogCodeGenerator.GetEpiserverCode(resource);

            string resourceFileId      = null;
            Field  resourceFileIdField = resource.GetField(FieldNames.ResourceFileId);

            if (resourceFileIdField != null && !resourceFileIdField.IsEmpty())
            {
                resourceFileId = resource.GetField(FieldNames.ResourceFileId).Data.ToString();
            }

            IEnumerable <XElement> metaFields = resource.Fields.Where(field => !_mappingHelper.SkipField(field.FieldType))
                                                .Select(field => _catalogElementFactory.GetMetaFieldValueElement(field));

            IEnumerable <XElement> parentEntries = parents.Select(parent => new XElement("EntryCode", parent.Key,
                                                                                         new XAttribute("IsMainPicture", IsMainPicture(parent, resourceFileId))));

            return(new XElement("Resource",
                                new XAttribute("id", resourceId),
                                new XAttribute("action", action),
                                new XElement("ResourceFields", metaFields),
                                GetInternalPaths(resource),
                                new XElement("ParentEntries", parentEntries)));
        }