Actually, you do not configure the Automapper in your plugin. You need to configure this at your plugin. The below code is working as expected at my nopcommerce 3.9 plugin. Hope it will help you. Please change the domain and ViewModel accordingly by yours.
public class PluginMapperConfiguration : IMapperConfiguration
{
/// <summary>
/// Get configuration
/// </summary>
/// <returns>Mapper configuration action</returns>
public Action<IMapperConfigurationExpression> GetConfiguration()
{
//TODO remove 'CreatedOnUtc' ignore mappings because now presentation layer models have 'CreatedOn' property and core entities have 'CreatedOnUtc' property (distinct names)
Action<IMapperConfigurationExpression> action = cfg =>
{
//products
cfg.CreateMap<Product, ProductModelPlugin>()
.ForMember(dest => dest.CustomProperties, mo => mo.Ignore()); //ignore property
cfg.CreateMap<ProductModelPlugin, Product>()
.ForMember(dest => dest.LimitedToStores, mo => mo.Ignore()); //ignore property
};
return action;
}
/// <summary>
/// Order of this mapper implementation
/// </summary>
public int Order
{
get { return 0; }
}
}
Then
public static class MappingExtension
{
public static TDestination MapTo<TSource, TDestination>(this TSource source)
{
return AutoMapperConfiguration.Mapper.Map<TSource, TDestination>(source);
}
public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination)
{
return AutoMapperConfiguration.Mapper.Map(source, destination);
}
public static Product ToEntity(this ProductModelPlugin model, Product destination)
{
return model.MapTo(destination);
}
public static ProductModelPlugin ToModelPlugin(this Product entity)
{
return entity.MapTo<Product, ProductModelPlugin>();
}
public static Product ToEntity(this ProductModelPlugin model)
{
return model.MapTo<ProductModelPlugin, Product>();
}
}
At controller
product = model.ToEntity(product);