(Lucene) Filter products that has any price for current user

I only want to show products that has a price for current user using Lucene. We’ve tried the following code in PriceFilterService, but the product is not visible

var priceListSystemIds = _priceListForUser.Value;

            var allPrices = new List<(int Min, int Max)> 
            {
                {(1, int.MaxValue) }
            };
            var countryId = _requestModelAccessor.RequestModel.CountryModel.SystemId;

            var optTagClause = new OptionalTagClause();

            var limitedTag = _fieldDefinitionService.Get<ProductArea>(ProductFieldNameConstants.LimitedToProductGroup).GetTagName();

            if (priceListSystemIds.Count > 0)
            {
                var limitedMandTag = new MandatoryTagClause();
                limitedMandTag.Tags.Add(new Tag(limitedTag, true));
                foreach (var item in priceListSystemIds)
                {
                    var name = _requestModelAccessor.RequestModel.Cart.IncludeVAT
                        ? TagNames.GetTagNameForPriceIncludingVAT(item, countryId)
                        : TagNames.GetTagNameForPriceExludingVAT(item, countryId);

                    request.ReadTags.Add(name);
                    foreach (var priceItem in allPrices)
                    {
                        limitedMandTag.Tags.Add(new RangeTag(name, priceItem.Min, priceItem.Max));
                    }
                }
                optTagClause.Tags.Add(limitedMandTag);
            }


            request.FilterTags.Add(optTagClause);

Litium version: 7.7.0

You are adding the price lists as into a MandatoryTagClause, which would require every one of the users’ price lists to have a price for a product.

Does it work if only the tag for LimitedToProductGroup is added in a MandatoryTagClause and the price lists are added into an OptionalTagClause? These are then both added to request.FilterTags.

That worked for me, thank you

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.