Skip to main content
added 12 characters in body
Source Link
gorhal
  • 318
  • 2
  • 7

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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": "Hedin"MyCompany.Commerce.Plugin.HedinPricing.IndexFields.PriceHandler, HedinMyCompany.Commerce.Plugin.Hedin"Pricing",
              "ComposerSource": {
                "PropertyName": "ListPrice"
              }
            }
          }

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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": "Hedin.Commerce.Plugin.Hedin.IndexFields.PriceHandler, Hedin.Commerce.Plugin.Hedin",
              "ComposerSource": {
                "PropertyName": "ListPrice"
              }
            }
          }

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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"
              }
            }
          }
added 98 characters in body
Source Link
gorhal
  • 318
  • 2
  • 7

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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"Hedin.Commerce.Plugin.PricingHedin.IndexFields.PriceHandler, MyCompanyHedin.Commerce.Plugin.Pricing"Hedin",
              "ComposerSource": {
                "PropertyName": "ListPrice"
              }
            }
          }

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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"
            }
          }

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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": "Hedin.Commerce.Plugin.Hedin.IndexFields.PriceHandler, Hedin.Commerce.Plugin.Hedin",
              "ComposerSource": {
                "PropertyName": "ListPrice"
              }
            }
          }
Source Link
gorhal
  • 318
  • 2
  • 7

Why not go all the way, lets borrow the code from the previous answer and than put in in the Commerce Engine.

  1. Create a custom index handler
  2. Update the json config - PlugIn.Search.Solr.PolicySet-1.0.0.json
  3. 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"
            }
          }