-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductVariantsExtractor.cs
More file actions
70 lines (58 loc) · 2.21 KB
/
Copy pathProductVariantsExtractor.cs
File metadata and controls
70 lines (58 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections.Generic;
using DancingGoat.Models;
namespace DancingGoat.Commerce
{
/// <summary>
/// Extractor of product-specific variants.
/// </summary>
public sealed class ProductVariantsExtractor
{
private readonly IEnumerable<IProductTypeVariantsExtractor> parametersExtractors;
public ProductVariantsExtractor(IEnumerable<IProductTypeVariantsExtractor> parametersExtractors)
{
this.parametersExtractors = parametersExtractors;
}
/// <summary>
/// Extract product variants and update the dictionary of variants.
/// </summary>
/// <param name="product">Product to process.</param>
/// <returns>Dictionary containing product variants.</returns>
public IDictionary<int, string> ExtractVariantsValue(IProductFields product)
{
var result = new Dictionary<int, string>();
foreach (var item in parametersExtractors)
{
var variants = item.ExtractVariantsValue(product);
if (variants != null)
{
foreach (var variant in variants)
{
result.Add(variant.Key, variant.Value);
}
}
}
return result;
}
/// <summary>
/// Extract product variants SKU code and update the dictionary of variants.
/// </summary>
/// <param name="product">Product to process.</param>
/// <returns>Dictionary containing product variant identifier as a key and product variant SKU code as a value.</returns>
public IDictionary<int, string> ExtractVariantsSKUCode(IProductFields product)
{
var result = new Dictionary<int, string>();
foreach (var item in parametersExtractors)
{
var variants = item.ExtractVariantsSKUCode(product);
if (variants != null)
{
foreach (var variant in variants)
{
result.Add(variant.Key, variant.Value);
}
}
}
return result;
}
}
}