/// <summary> /// <ProductCrossReference ProductID="CAP-1" Type="Components"> /// <MetaData> /// <Value AttributeID="Component Quantity">1</Value> /// <Value AttributeID="Component Requirement Type" ID="CRT-110959">Optional</Value> /// </MetaData> /// </ProductCrossReference> /// </summary> /// <param name="linkedID"></param> /// <param name="compRefEl"></param> /// <returns></returns> private PIMProductReference ParseProductReferences(string linkedID, XElement compRefEl) { var xrefType = GetAttributeValue(compRefEl, "Type"); var componentProdNumber = GetAttributeValue(compRefEl, "ProductID"); // Skip where not component product if (String.IsNullOrWhiteSpace(xrefType) || String.IsNullOrWhiteSpace(componentProdNumber)) { return(null); } var prodRef = new PIMProductReference() { ReferenceType = xrefType, ParentLinkedId = linkedID, ProductNumber = componentProdNumber }; var valueEls = compRefEl.XPathSelectElements("MetaData/Value"); if (valueEls == null) { return(prodRef); } foreach (var valueEl in valueEls) { var attrID = GetAttributeValue(valueEl, "AttributeID"); if (string.IsNullOrWhiteSpace(attrID)) { continue; } // Ugly switch (attrID.ToLower()) { case "component quantity": var compQty = GetNodeText(valueEl); int qty; if (Int32.TryParse(compQty, out qty)) { prodRef.Quantity = qty; } else { prodRef.Quantity = 1; } break; case "component requirement type": var compReqTypeId = GetAttributeValue(valueEl, "ID"); prodRef.ComponentRequirementTypeID = String.IsNullOrWhiteSpace(compReqTypeId) ? DEFAULT_REQUIREMENT_TYPE : CleanLOVIDByAttribute(attrID, compReqTypeId); break; } } return(prodRef); }
public List <PIMProductReference> GetProductReferences() { var qry = from lvl in XmlDocument.Descendants("Product") select lvl; List <PIMProductReference> prodRefs = new List <PIMProductReference>(); // Loop products foreach (var item in qry) { var prodIDAttr = item.Attribute("ID"); var prodID = prodIDAttr != null ? prodIDAttr.Value : null; // Skip where no parent if (String.IsNullOrWhiteSpace(prodID)) { continue; } var compRefs = item.XPathSelectElements("ProductCrossReference[@Type='Components']"); foreach (var compRef in compRefs) { var productIDAttr = compRef.Attribute("ProductID"); string componentProdNumber = productIDAttr != null ? productIDAttr.Value : null; // Skip where not component product if (String.IsNullOrWhiteSpace(componentProdNumber)) { continue; } var prodRef = new PIMProductReference() { ParentProductNumber = prodID, ProductNumber = componentProdNumber }; prodRefs.Add(prodRef); var compQtyEl = compRef.XPathSelectElement("//Value[@AttributeID='Component Quantity']"); int qty; if (compQtyEl != null && Int32.TryParse(compQtyEl.Value, out qty)) { prodRef.Quantity = qty; } else { prodRef.Quantity = 1; } var compReqTypeEl = compRef.XPathSelectElement("//Value[@AttributeID='Component Requirement Type']"); if (compReqTypeEl != null) { var compReqTypeIDAttr = compReqTypeEl.Attribute("ID"); prodRef.ComponentRequirementTypeID = compReqTypeIDAttr == null ? DEFAULT_REQUIREMENT_TYPE : CleanLOVIDByAttribute(null, compReqTypeIDAttr.Value); } } } return(prodRefs); }