Exemplo n.º 1
0
        private async Task <bool> HandleSkuUpdateAsync(int entityId,
                                                       Entity channelEntity,
                                                       ConnectorEvent connectorEvent,
                                                       List <StructureEntity> structureEntities)
        {
            bool  resourceIncluded = false;
            Field currentField     = RemoteManager.DataService.GetField(entityId, "SKUs");

            List <Field> fieldHistory = RemoteManager.DataService.GetFieldHistory(entityId, "SKUs");

            Field previousField = fieldHistory.FirstOrDefault(f => f.Revision == currentField.Revision - 1);

            string oldXml = String.Empty;

            if (previousField?.Data != null)
            {
                oldXml = (string)previousField.Data;
            }

            string newXml = String.Empty;

            if (currentField.Data != null)
            {
                newXml = (string)currentField.Data;
            }

            PimFieldAdapter.CompareAndParseSkuXmls(oldXml, newXml, out List <XElement> skusToAdd, out List <XElement> skusToDelete);

            foreach (XElement skuToDelete in skusToDelete)
            {
                string skuId = skuToDelete.Attribute("id")?.Value;
                await _epiApi.DeleteSkuAsync(skuId);
            }

            if (skusToAdd.Count > 0)
            {
                await PublishEntitiesAsync(channelEntity, connectorEvent, structureEntities);

                resourceIncluded = true;
            }

            return(resourceIncluded);
        }