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);
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.
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.