Yo,
I noticed a thing that happens when the ProductManufacturerId column in EcomProducts is a whitespace (or has a whitespace) in it.
Manufacturer.GetManufacturerById() returns null (because of the whitespace) so the code inside ManufacturerIDValueMapper.MapValues() returns a null reference when trying to read the id for the given manufacturer.
Changing string.IsNullOrEmpty to string.IsNullOrWhitespace inside ManufacturerIDValueMapper.MapValues() and Manufacturer.GetManufacturerById() and adding null checks (? behind the object reference) should fix this:
public class ManufacturerIDValueMapper : ValueMapperBase
{
public override IEnumerable<FieldValueMapping> MapValues(IEnumerable<string> terms)
{
var mappings = new List<FieldValueMapping>();
foreach (var term in terms)
{
var manufacturerItem = Manufacturer.GetManufacturerById(term);
if (!string.IsNullOrEmpty(manufacturerItem.Id))
if (!string.IsNullOrWhiteSpace(manufacturerItem?.Id))
{
mappings.Add(new FieldValueMapping() { Key = manufacturerItem.Id, Value = manufacturerItem.Name });
}
}
return mappings;
}
}
and
public static Manufacturer GetManufacturerById(string id)
{
Manufacturer manufacturer = null;
if (!string.IsNullOrEmpty(id) && CachedManufacturers.TryGetValue(id, out manufacturer))
if (!string.IsNullOrWhiteSpace(id) && CachedManufacturers.TryGetValue(id, out manufacturer))
{
return manufacturer;
}
return null;
}
Best regards,
Arnór