Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.
- Create a custom index handler
- Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
- Do a bootstrap, and don't forget to stop start your Minions service. So the the index minions are updated.
Custom Index handler:
public class PriceHandler : AbstractIndexFieldHandler
{
public ComposerValueSource ComposerSource { get; set; } = new ComposerValueSource(string.Empty, string.Empty);
public override object ComposeValue(object source, ConcurrentDictionary<string, object> context)
{
if (context == null || !(source is CatalogItemBase catalogItemBase))
return null;
if (!(catalogItemBase is SellableItem))
return null;
SellableItem sellabelItem = catalogItemBase as SellableItem;
if (ComposerSource.PropertyName.Equals("ListPrice"))
{
var pricesPolicy = sellabelItem.GetPolicies<ListPricingPolicy>();
var prices = pricesPolicy.SelectMany(pricePolicy => pricePolicy.Prices).Select(money => money.Amount)
.ToList();
return prices.FirstOrDefault();
}
return null;
}
}
PlugIn.Search.Solr.PolicySet-1.0.0.json:
{
"$type": "Sitecore.Commerce.Plugin.Search.Solr.SolrIndexFieldConfiguration, Sitecore.Commerce.Plugin.Search.Solr",
"Name": "ListPrice",
"Type": "System.Decimal",
"Handler": {
"$type": "MyCompany.Commerce.Plugin.Pricing.IndexFields.PriceHandler, MyCompany.Commerce.Plugin.Pricing",
"ComposerSource": {
"PropertyName": "ListPrice"
}
}
}