Developer forum

Forum » Development » TotalPrice is deprecated in DiscountInfoCollection

TotalPrice is deprecated in DiscountInfoCollection

Anders Ebdrup
Reply

Hello Dynamicweb,

I need to retrieve the discounted price for a product through the API. At the moment, it seems like I have to do something like this:

var discountCollection = new DiscountInfoCollection(priceContext, product, null, 0); 
var discountPrice = discountCollection.TotalPrice;

However, the TotalPrice property is deprecated with the following message:

Use Services.DiscountService.GetProductDiscountPrice() instead.

The issue is that GetProductDiscountPrice() appears to be internal in DiscountService, and the DefaultDiscountService class is also internal.

What is the recommended way to retrieve the discounted product price in Dynamicweb 10?

 

Best regards, Anders

 


Replies

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders,

The DiscountService you mentioned - via Services.DiscountService.GetProductDiscountPrice() - is not internal. However, it's marked as experimental, which is probably the warning/error you see when you call it.

You should be able to suppress it:

#pragma warning disable DWEX100001
    Services.DiscountService.GetProductDiscountPrice()
#pragma warning restore DWEX100001

 

Tell me if this works.

/Kristian

 
Anders Ebdrup
Reply

Hi Kristian,

Thanks for the reply, but for me the methods seem to be internal - please find this screen dumps:

 

Best regards, Anders

 

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Ah - so we're confusing the two DiscountServices.

 

The message "Use Services.DiscountService.GetProductDiscountPrice() instead.", actually means that you should call the Services.DiscountService - not Services.Discounts. The first is the newest version, the latter is the old one with the internal method you mentioned.

The service to use has this full namespace: "Dynamicweb.Ecommerce.Orders.Adjustments.DiscountService".

 

Regarding your screenshots...

The first points to the old service - but the message "Use Services.DiscountService.GetProductDiscountPrice() instead." didn't say to use the old service.

The second points to our internal implementation of the new DiscountService.

 

I hope this clears up the confusion.

/Kristian

 

You must be logged in to post in the forum