Overriding conventions for indexing

Vote:
 

Hi,

We have a quite large Commerce Catalog, and are indexing the products in Find. But since we don't want all data to be indexed (and to save us some time when indexing), we created conventions for removing prices. We followed this recipe:
https://world.episerver.com/documentation/developer-guides/commerce/search/find-integration/overriding-default-conventions/

Our implementation:

[InitializableModule]
 [ModuleDependency(typeof(FindCommerceInitializationModule))]
 public class SiteFindCommerceInitializationModule : IConfigurableModule
 {
       public void ConfigureContainer(ServiceConfigurationContext context)
       {
                context.Services.AddSingleton();
       }


       //... more mode

 }




and added the following conventions in the implementation:

    public class SiteCatalogContentClientConventions : CatalogContentClientConventions
    {
        protected override void ApplyPricingConventions(TypeConventionBuilder conventionBuilder)
        {
            base.ApplyPricingConventions(conventionBuilder);
            conventionBuilder
                .ExcludeField(x => x.DefaultPrice())
                .ExcludeField(x => x.Prices())
                .ExcludeField(x => x.GetPrices());
        }

        protected override void ApplyPriceConventions(TypeConventionBuilder conventionBuilder)
        {
            base.ApplyPriceConventions(conventionBuilder);
            conventionBuilder.ExcludeField(x => x.CustomerPricing);
        }

        protected override void ApplyIndexedPricesConventions(TypeConventionBuilder conventionBuilder)
        {
            base.ApplyIndexedPricesConventions(conventionBuilder);
            conventionBuilder.ExcludeField(x => x.Prices());
        }
        


But we still get the prices in the Find index.

In addition to remove the prices, we added this convention to remove inventories. Which works just fine.

        protected override void ApplyIStockPlacementConventions(TypeConventionBuilder conventionBuilder)
        {
            base.ApplyIStockPlacementConventions(conventionBuilder);
            conventionBuilder.ExcludeField(x => x.Inventories());
        }

We are running on version: 11.2.4

#188014
Edited, Feb 08, 2018 13:33
Vote:
 

Not sure why do you have to call  .ExcludeField(x => x.GetPrices());, but that does not seem to be necessary. It might be the culprit.

You can just remove the call to base method and just Exclude the PriceReference property in your method 

#188021
Feb 08, 2018 19:23
Vote:
 

Hi Quan,

I'm trying everything - that's why:

These are the prices I get in Find:

    "Prices$$nested": [
        {
            "CustomerPricing": {
                "PriceCode$$string": "",
                "$type": "Mediachase.Commerce.Pricing.CustomerPricing, Mediachase.Commerce",
                "PriceTypeId": 0
            },
            "___types": [
                "EPiServer.Commerce.SpecializedProperties.Price",
                "System.Object",
                "System.ICloneable"
            ],
            "ValidFrom$$date": "2017-01-01T00:00:00Z",
            "$type": "EPiServer.Commerce.SpecializedProperties.Price, EPiServer.Business.Commerce",
            "UnitPrice": {
                "Amount$$number": "8.800000000",
                "$type": "Mediachase.Commerce.Money, Mediachase.Commerce",
                "Currency": {
                    "CurrencyCode$$string": "NOK"
                }
            },
            "MarketId": {
                "$type": "Mediachase.Commerce.MarketId, Mediachase.Commerce",
                "Value$$string": "10002"
            },
            "MinQuantity$$number": 1,
            "ValidUntil$$date": "2199-01-01T00:00:00Z"
        },

I have tried this:


protected override void ApplyPricingConventions(TypeConventionBuilder<IPricing> conventionBuilder)
{
base.ApplyPricingConventions(conventionBuilder);
conventionBuilder
.ExcludeField(x => x.PriceReference);
}

And this:

protected override void ApplyPricingConventions(TypeConventionBuilder<IPricing> conventionBuilder)
{
base.ApplyPricingConventions(conventionBuilder);
conventionBuilder
.ExcludeField(x => x.DefaultPrice())
.ExcludeField(x => x.Prices())
.ExcludeField(x => x.PriceReference);
}

And this:

       protected override void ApplyPricingConventions(TypeConventionBuilder conventionBuilder)
        {
            base.ApplyPricingConventions(conventionBuilder);
            conventionBuilder
                .ExcludeField(x => x.DefaultPrice())
                .ExcludeField(x => x.Prices())
                .ExcludeField(x => x.GetPrices());
        }

And this:

protected override void ApplyPricingConventions(TypeConventionBuilder<IPricing> conventionBuilder)
{
base.ApplyPricingConventions(conventionBuilder);
conventionBuilder
.ExcludeField(x => x.PriceReference)
.ExcludeField(x => x.DefaultPrice())
.ExcludeField(x => x.Prices())
.ExcludeField(x => x.GetPrices())
.ExcludeField(x => x.GetCustomerPrices());
}



#188045
Edited, Feb 09, 2018 10:51
Vote:
 

How about this?


protected override void ApplyPricingConventions(TypeConventionBuilder<IPricing> conventionBuilder)
{
conventionBuilder
.ExcludeField(x => x.PriceReference);
}
#188046
Feb 09, 2018 10:53
Vote:
 

And that worked like a charm! Thanks!

#188047
Feb 09, 2018 11:04
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.