-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeeParametersExtractor.cs
More file actions
49 lines (42 loc) · 1.66 KB
/
Copy pathCoffeeParametersExtractor.cs
File metadata and controls
49 lines (42 loc) · 1.66 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
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CMS.ContentEngine;
using DancingGoat.Models;
namespace DancingGoat.Commerce
{
/// <inheritdoc cref="IProductTypeParametersExtractor"/>
public class CoffeeParametersExtractor : IProductTypeParametersExtractor
{
private readonly ITaxonomyRetriever taxonomyRetriever;
public CoffeeParametersExtractor(ITaxonomyRetriever taxonomyRetriever)
{
this.taxonomyRetriever = taxonomyRetriever;
}
/// <inheritdoc/>
public async Task ExtractParameter<T>(IDictionary<string, string> parameters, T product, string languageName, CancellationToken cancellationToken)
{
if (product is ProductCoffee coffee)
{
var identifiers = coffee.CoffeeProcessing.Select(x => x.Identifier)
.Union(coffee.CoffeeTastes.Select(x => x.Identifier));
var taxonomies = await taxonomyRetriever.RetrieveTags(identifiers, languageName, cancellationToken);
foreach (var taxonomy in taxonomies)
{
var key = coffee.CoffeeProcessing.Any(x => x.Identifier == taxonomy.Identifier)
? "Processing"
: "Taste";
if (parameters.TryGetValue(key, out string value))
{
parameters[key] = $"{value}, {taxonomy.Name}";
}
else
{
parameters.Add(key, taxonomy.Name);
}
}
}
}
}
}