/// <summary> /// Are attributes equal /// </summary> /// <param name="attributes1">The attributes of the first product variant</param> /// <param name="attributes2">The attributes of the second product variant</param> /// <returns>Result</returns> public static bool AreProductAttributesEqual(string attributes1, string attributes2) { bool attributesEqual = true; if (ProductAttributeHelper.ParseProductVariantAttributeIds(attributes1).Count == ProductAttributeHelper.ParseProductVariantAttributeIds(attributes2).Count) { var pva1Collection = ProductAttributeHelper.ParseProductVariantAttributes(attributes2); var pva2Collection = ProductAttributeHelper.ParseProductVariantAttributes(attributes1); foreach (var pva1 in pva1Collection) { foreach (var pva2 in pva2Collection) { if (pva1.ProductVariantAttributeId == pva2.ProductVariantAttributeId) { var pvaValues1Str = ProductAttributeHelper.ParseValues(attributes2, pva1.ProductVariantAttributeId); var pvaValues2Str = ProductAttributeHelper.ParseValues(attributes1, pva2.ProductVariantAttributeId); if (pvaValues1Str.Count == pvaValues2Str.Count) { foreach (string str1 in pvaValues1Str) { bool hasAttribute = false; foreach (string str2 in pvaValues2Str) { if (str1.Trim().ToLower() == str2.Trim().ToLower()) { hasAttribute = true; break; } } if (!hasAttribute) { attributesEqual = false; break; } } } else { attributesEqual = false; break; } } } } } else { attributesEqual = false; } return(attributesEqual); }
/// <summary> /// Finds a product variant attribute combination by attributes stored in XML /// </summary> /// <param name="productVariantId">Product variant identifier</param> /// <param name="attributesXml">Attributes in XML format</param> /// <returns>Found product variant attribute combination</returns> public static ProductVariantAttributeCombination FindProductVariantAttributeCombination(int productVariantId, string attributesXml) { //existing combinations var combinations = ProductAttributeManager.GetAllProductVariantAttributeCombinations(productVariantId); if (combinations.Count == 0) { return(null); } foreach (var combination in combinations) { bool attributesEqual = ProductAttributeHelper.AreProductAttributesEqual(combination.AttributesXml, attributesXml); if (attributesEqual) { return(combination); } } return(null); }