ProductPriceModelBuilder SetFormattedPrice object reference to an instance

We are running a task in Litium 8, where we call ProductPriceModelBuilder.Build with all the required parameters, but we get an object reference exception on “SetFormattedPrice” inside that builder.

What I can see on my end is that CartAccessor.CartContext, cant be resolved within a Task, it’s null. Is there a workaround?

When you don’t have a user context, I think it’s better to use the IPriceCalculator.
And you can use the currency to format the price in the same way as SetFormattedPrice

Something like this

var calculatorArgs2 = new PriceCalculatorArgs
            {
                CurrencySystemId = currencySystemId,
                DateTimeUtc = DateTimeOffset.UtcNow,
                WebSiteSystemId = webSiteSystemId,
                CountrySystemId = countryId,
                SourceId = "From task"
            };

            var calculatorItemArgs = new PriceCalculatorItemArgs
            {
                VariantSystemId = variant.SystemId,
                Quantity = 1M
            };

            return _priceCalculator.GetListPrices(calculatorArgs2, calculatorItemArgs).TryGetValue(calculatorItemArgs.VariantSystemId, out var calculatorResult2);

But that wont include campaign prices for Litium 8. Atleast I havent found how to search for them.

Would also like to have same logic to build the price for listning and productpage, and as they are doing it with this PriceProductBuilder and it fails (seems to be on a boolean to show wat or not becuase object is null as it’s beeing resolved from a HttpContext item) Would like to have a workaround to go on the actual priceitem as the other object is null.

I think you should be able to use DiscountPriceCalculatorArgs with IDiscountPriceCalculator in the same way.

But yea, you wont get back the same object as in ProductPriceModelBuilder. But you should be able to build your own.

But mabye the Tier price will be hard…

It is a good solution @Ericsj11, what I will do instead as a workaround is to do HTTP call from our Task to ourself, that way we will have a HttpContext and litium can resolve cartcontext.

But still, would like Litiums answer on this. Is this by design or a bug in litium 8.

1 Like

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