# ProductPriceModelBuilder SetFormattedPrice object reference to an instance

**URL:** <https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523>\
**Category:** Questions\
**Tags:** litium-8\
**Created:** [March 29, 2022, 12:23pm UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523 "2022-03-29T12:23:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)\
**Post date:** [March 29, 2022, 12:23pm UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/1 "2022-03-29T12:23:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ericsj11](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ericsj11/32/899_2.png) [@Ericsj11](https://forum.litium.com/u/Ericsj11)\
**Post date:** [March 30, 2022, 6:31am UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/2 "2022-03-30T06:31:04Z")

</div>

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

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)\
**Post date:** [March 30, 2022, 6:37am UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/3 "2022-03-30T06:37:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)\
**Post date:** [March 30, 2022, 6:41am UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/4 "2022-03-30T06:41:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ericsj11](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ericsj11/32/899_2.png) [@Ericsj11](https://forum.litium.com/u/Ericsj11)\
**Post date:** [March 30, 2022, 7:20am UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/5 "2022-03-30T07:20:33Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)\
**Post date:** [March 30, 2022, 7:50am UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/6 "2022-03-30T07:50:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [April 27, 2022, 7:51am UTC](https://forum.litium.com/t/productpricemodelbuilder-setformattedprice-object-reference-to-an-instance/2523/7 "2022-04-27T07:51:03Z")

</div>

Closed on April 27, 2022, 7:51am UTC

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