Developer forum

Forum » Development » PriceProvider infinite loop

PriceProvider infinite loop

Gaëtan Di Caro
Reply

Hello,

 

I'm trying to implement a simple custom price provider (users have a fixed discount percentage on top of the regular price, including other discounts). I tried the example here : http://doc.dynamicweb.com/training-certification/t3-platform-developer/t3-platform-developer/3-3-extending-ecommerce

However the example doesn't work. First of all, isLoggedIn doesn't exist anymore, and it just goes in an infinite loop. My guess is that it's because it calls product.Price, which calls the custom provider, which calls product.Price, and so on.

What is the correct way to implement a price provider in DW 9 ?

 

Thanks


Replies

 
Gaëtan Di Caro
Reply

Nevermind, I found the solution : I just call the default price provider to get the default price.

var defaultPriceProvider = new DefaultPriceProvider();
var defaultPrice = defaultPriceProvider.FindPrice(product, quantity, variantId, currency, unitId, user);
priceRaw = new PriceRaw(defaultPrice.Price * 0.75, currency);

 

It would still be nice to update the documentation with working code.

 
Martin Vang
Martin Vang
Reply

Hi Gaƫtan,

I don't know about the infinite loop. I would need to take a look at the code to understand how that could happen.

If you want to do an update of some part of our api that triggers notifications, but don't want these notifications to fire, that is actually a built-in support for this:

using (var context = new NotificationContext(NotificationContext.NotificationState.SuppressNotifications))
{

//Code in context that does not trigger notifications

}

All code inside this context will not trigger notifications, which means, that subscribers can safely update data that would normally result in infinite recursion.

Regarding code examples that are out of date: Thank you for informing us. :)

BR

Martin

 
Dynamicweb Employee
Carsten Boll
Reply

Hi guys, thank you for bringing this to my attention. The code example has been corrected :)

 

You must be logged in to post in the forum