# Campaign prices stop working then adding custom IIndexingProviderPreProcessor

**URL:** <https://forum.litium.com/t/campaign-prices-stop-working-then-adding-custom-iindexingproviderpreprocessor/469>\
**Category:** Questions\
**Created:** [January 9, 2019, 12:15pm UTC](https://forum.litium.com/t/campaign-prices-stop-working-then-adding-custom-iindexingproviderpreprocessor/469 "2019-01-09T12:15:53Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [January 10, 2019, 12:14pm UTC](https://forum.litium.com/t/campaign-prices-stop-working-then-adding-custom-iindexingproviderpreprocessor/469/11 "2019-01-10T12:14:42Z")

</div>

The problem you are getting is that `IIndexingProviderPreProcessor` is initiated before the module _ECommerce_ have been initiated and the implementation of `ICampaignPriceCalculator` is checking if the _ECommerce_ have been initialized when it is created and in this case it says that the **_ECommerce_ does not exists** and **skipping all usage of the campaign engine** , both for indexing and to requests to the public website.

If you build an preprocessor like the following we are initializing the `ICampaignPriceCalculator` at a later stage.

```auto
using System;
using System.Linq;
using Litium.Foundation.Modules.CMS;
using Litium.Foundation.Modules.ECommerce;
using Litium.Foundation.Modules.ECommerce.Carriers;
using Litium.Foundation.Modules.ECommerce.Plugins.PriceCalculator;
using Litium.Foundation.Modules.ProductCatalog.Search;
using Litium.Foundation.Search.Providers;
using Litium.Framework.Search.Indexing;

namespace Litium.Accelerator.Search.Filtering
{
    internal class SetCampaignPriceFromCampaignPriceCalculator : IIndexingProviderPreProcessor
    {
        private ICampaignPriceCalculator _campaignPriceCalculator;

        public IndexDocument PreProcessDocument(IndexDocument document, string indexName)
        {
            if (ProductCatalogSearchDomains.Products.Equals(indexName, StringComparison.OrdinalIgnoreCase))
            {
                var articleIds = document.Tags.Where(x => x.Name.Equals(TagNames.VariantSystemId, StringComparison.OrdinalIgnoreCase)).Select(x => (Guid)x.OriginalValue).ToList();
                foreach (var item in articleIds
                    .Select(x => GetCampaignPrice(x, true)))
                {
                    document.Tags.Add(new ReadableDocumentTag("campaignprice-with-vat-from-campaign-engin", item));
                }
            }
            return document;
        }

        public decimal GetCampaignPrice(Guid variantId, bool withVat = false)
        {
            var campaignPriceCalculator = _campaignPriceCalculator ?? (ModuleECommerce.ExistsInstance ? (_campaignPriceCalculator = IoC.Resolve<ICampaignPriceCalculator>()) : null);
            if (campaignPriceCalculator == null)
            {
                return 0M;
            }

            var currency = CurrentState.Current.WebSite.Currency;
            var language = CurrentState.Current.WebSite.Language;
            var websiteId = CurrentState.Current.WebSite.ID;
            var token = CurrentState.Current.Token;

            if (currency == null || language == null || websiteId == Guid.Empty)
            {
                return 0M;
            }

            var priceCalculatorArgs = new CampaignPriceCalculatorArgs
            {
                CurrencySystemId = currency.ID,
                DateTimeUtc = DateTime.Now,
                VariantSystemId = variantId,
                Quantity = 1,
                WebSiteID = websiteId,
                UserID = token.UserID,
                OrderCarrier = new OrderCarrier()
            };

            return campaignPriceCalculator.GetCampaignPrices(priceCalculatorArgs)
                .TryGetValue(priceCalculatorArgs.VariantSystemId, out var listPrice)
                ? (withVat ? listPrice.CampaignPriceWithVAT : listPrice.CampaignPrice)
                : 0M;
        }
    }
}

```

---

_[View the full topic](https://forum.litium.com/t/campaign-prices-stop-working-then-adding-custom-iindexingproviderpreprocessor/469)._
