Developer forum

Forum » Development » Stack overflow exceptions in custom price providers

Stack overflow exceptions in custom price providers

Allan Iversen
Allan Iversen
Reply

Hi!

Periodically, we experience getting stack overflow errors (0xc00000fd) in our price providers when we call in this call Dynamicweb.Ecommerce.Common.Context.Cart - typically to get current number of item lines. It seems that it periodically starts to loop through the same code for fetching price.

In the forum, challenges have previously been reported with stack overflow errors in price providers, but this should be resolved by now? Is it the same that I experience now or a variety of it?

We have seen it on versions 9.8.11, 9.9.4 and 9.9.8.

Is there any way to avoid this? - any workaround?


Replies

 
Nicolai Pedersen
Reply

Hi Allan

Can you provide some stack trace?

Using Dynamicweb.Ecommerce.Common.Context.Cart and anything else from context can be a big problem with price providers. Price providers will i.e. run on a checkout call back - and that callback does not have a context, and does not have a cart (because it is another session). Also the price provider might be called from PIM feeds and other scenarios where there is no context. So in the price provider you cannot use session and context based stuff and expect it to work without fallbacks. So at least do null checks and provide fallback logic.

Using Dynamicweb.Ecommerce.Common.Context.Cart in the priceprovider does sound like a bad thing. Because it will potentially change the price of a product depending on the cart, which is counter intuitive if you ask me. Another solution is to add a discount instead.

BR Nicolai

 
Allan Iversen
Allan Iversen
Reply

Hi Nicolai

In one of our cases the unit price of specific products are based on other products within same range/style (and color/sizes) - also a given discount on top of that is based on that. We do need to know what is already in customer's cart.

I have made precautions for the looping but I really would want to avoid this.

Would I be able to fetch the current numbers of lines without starting up order price calculations?

Allan

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Allan

If that is what you need, go with it. But I would say that logically prices should be based on something you know before you make an order, anything else is a discount.

Stack overflow exception sounds like an endless loop, and that is what you would potentially get if you try to calculate a products price based on the cart, and the cart prices are based on the products price that depends on the order that depends on the product etc... You see the problem? A classic hen and the egg problem.

Using Common.Context.Cart can and will trigger price calculations in some situations since the cart can be loaded when a user comes back etc. It also handles a ton of other stuff like cart contexts, session, cookies, cart expiration rules etc.

My best bet is to get the cart directly like this: Services.Orders.GetById(cartId)and then somehow store the cart id in a place where you can get hold of it. But again, that cart id can be based on previous cart sessions coming from the user, a cookie or from session depending on your flow and your setup. And there is also cart context and cart expiration to take into consideration. So if you go with this approach, you can easily run into a scenario where the cart id you find with your own logic, does not match the one Dynamicweb would find.

You might be able to store the right cart id in i.e. a session using a pageloaded notification subscriber where you use common.context.cart, take the ID from that, store it in a session variable, and then in your price provider get that cart id to call the orderservice. Remember session null check. The order object you get from the service will have an orderlines collection that you can iterate. The order service will cache the object, so it will not get retrieved from database on each call.

Be careful of performance.

BR Nicolai

Votes for this answer: 1
 
Allan Iversen
Allan Iversen
Reply

Hi Nicolai,

Generally I do agree with that - it is a discounted price. Taking the informative aspect into consideration, we do need the "discounted" unit price.

If this behaviour was consistent the flaw was obvious but this happens periodically - maybe due to lack of price for certain products.

I will have to look into that.

Thanks for your help.

 
Nicolai Pedersen
Reply

It will happen when the cart is recalculated. That can happen if the session runs out and the cart is reloaded. Or if the user has been away and logs in again. It can also happen on server callbacks from payment gateways or as part of the live integration if that exists. Just to mention a few.

 

You must be logged in to post in the forum