@@ -180,6 +180,11 @@ public virtual void ClearCachedAttributeValues()
180
180
}
181
181
182
182
public virtual Multimap < int , string > DeserializeProductVariantAttributes ( string attributesXml )
183
+ {
184
+ return DeserializeAttributesXml ( attributesXml , null ) ;
185
+ }
186
+
187
+ private Multimap < int , string > DeserializeAttributesXml ( string attributesXml , int [ ] includeAttributesIds = null )
183
188
{
184
189
var attrs = new Multimap < int , string > ( ) ;
185
190
if ( String . IsNullOrEmpty ( attributesXml ) )
@@ -195,7 +200,8 @@ public virtual Multimap<int, string> DeserializeProductVariantAttributes(string
195
200
string sid = node1 . Attribute ( "ID" ) . Value ;
196
201
if ( sid . HasValue ( ) )
197
202
{
198
- if ( int . TryParse ( sid , out var id ) )
203
+ if ( int . TryParse ( sid , out var id ) &&
204
+ ( includeAttributesIds == null || includeAttributesIds . Contains ( id ) ) )
199
205
{
200
206
// ProductVariantAttributeValue/Value
201
207
foreach ( var node2 in node1 . Descendants ( "Value" ) )
@@ -326,6 +332,11 @@ public virtual bool AreProductAttributesEqual(string attributeXml1, string attri
326
332
var attributes1 = DeserializeProductVariantAttributes ( attributeXml1 ) ;
327
333
var attributes2 = DeserializeProductVariantAttributes ( attributeXml2 ) ;
328
334
335
+ return AreProductAttributesEqual ( attributes1 , attributes2 ) ;
336
+ }
337
+
338
+ private bool AreProductAttributesEqual ( Multimap < int , string > attributes1 , Multimap < int , string > attributes2 )
339
+ {
329
340
if ( attributes1 . Count != attributes2 . Count )
330
341
return false ;
331
342
@@ -383,9 +394,14 @@ public virtual ProductVariantAttributeCombination FindProductVariantAttributeCom
383
394
if ( combinations . Count == 0 )
384
395
return null ;
385
396
397
+ var listTypeValues = ParseProductVariantAttributeValues ( attributesXml ) ;
398
+ var listTypeAttributesIds = listTypeValues . Select ( x => x . ProductVariantAttributeId ) . ToArray ( ) ;
399
+ var listTypeAttributesMap = DeserializeAttributesXml ( attributesXml , listTypeAttributesIds ) ;
400
+
386
401
foreach ( var combination in combinations )
387
402
{
388
- bool attributesEqual = AreProductAttributesEqual ( combination . AttributesXml , attributesXml ) ;
403
+ var combinationAttributesMap = DeserializeProductVariantAttributes ( combination . AttributesXml ) ;
404
+ bool attributesEqual = AreProductAttributesEqual ( combinationAttributesMap , listTypeAttributesMap ) ;
389
405
if ( attributesEqual )
390
406
return _productAttributeService . GetProductVariantAttributeCombinationById ( combination . Id ) ;
391
407
}
0 commit comments