Greetings
I have a fee discount i want to apply to the current shipping fee if product selected is part of a group and a special shippingmethod has been chosen.
I extend the feeprovider, since I think thats the right one, please correct me if I am wrong and the code goes some thing like this
[AddInName("ShipmentDiscountProvider"), AddInDescription("Adds a discount to the order if order is sent and there is discount on group"),
AddInActive(true), AddInIsAdditional(false)]
public class ShipmentDiscountProvider : FeeProvider
{
public override Dynamicweb.eCommerce.Prices.PriceRaw FindFee(Order Order)
{
var fee = Order.ShippingFee;
}
}
Plus some other code witch does the actual logic for me. However when i try to access the Order.ShippingFee I get a stack.overflow exception. And if I go throught the order in debugger i get an aborted error at the price field.
I am aware that the code shown needs a return value, however this is only a snippet of the code :)
Can anyone tell me how to retrieve the shipmentFee from the active order?
With kind regards
Christoffer Andersen
Developer forum
E-mail notifications
custom fee provider
Christoffer Andersen
Posted on 04/11/2011 13:26:12
Replies
Jeppe Eriksson Agger
Posted on 04/11/2011 14:12:10
This post has been marked as an answer
Hi Christoffer
The reason you get a StackOverflow is because you get a circular reference. Your FeeProvider calls the Order.ShippingFee property which in turn calls your FeeProvider and so on.
You might want to consider creating a complete Shipping Fee Provider from the ground up instead of giving a discount on the fee calculated by another FeeProvider. This should make it so you don't have to call Order.ShippingFee from the provider.
If you want to continue on the path you're on now then you need to break the circle by returning null if the current invoke originated from your own provider. Maybe look at the Stack Trace or something.
- Jeppe
The reason you get a StackOverflow is because you get a circular reference. Your FeeProvider calls the Order.ShippingFee property which in turn calls your FeeProvider and so on.
You might want to consider creating a complete Shipping Fee Provider from the ground up instead of giving a discount on the fee calculated by another FeeProvider. This should make it so you don't have to call Order.ShippingFee from the provider.
If you want to continue on the path you're on now then you need to break the circle by returning null if the current invoke originated from your own provider. Maybe look at the Stack Trace or something.
- Jeppe
Votes for this answer: 0
Imar Spaanjaars
Posted on 04/11/2011 14:31:24
Or better yet, add something to HttpContext.Current.Items the first time your code gets executed. Then check if that value exists and return if it does....Maybe look at the Stack Trace or something.
Imar
Jeppe Eriksson Agger
Posted on 04/11/2011 14:34:12
I thought of that, but the issue would be that if (and we all know that it's a real possibility) Fees/Price is called multiple times on a page load, the corrected fee would not be calculated the second, third, ... times. That's why I recommended the Stack Trace.
- Jeppe
Imar Spaanjaars
Posted on 04/11/2011 14:54:38
I see. Thanks for the update; didn't realize that....
Imar
Imar
Imar Spaanjaars
Posted on 04/11/2011 14:56:16
Unless, maybe, you only retrieve the fee the first time and store that in HttpContext. This way, the code can fire multiple times, but it's only retrieved once. Not sure if that would be enough as it may have been changed between the first and later times it is accessed.
Imar
Imar
Jeppe Eriksson Agger
Posted on 04/11/2011 15:05:54
That could work if the value doesn't change, as you mention. Another way could be to have something like this:
if (HttpContext.Current.Items.Contains(cacheKey) && HttpContext.Current.Items[cacheKey] != null) return; // Begin logic HttpContext.Current.Items.Add(cacheKey, someObject); // Have logic here Order.ShippingFee; //Finished with logic HttpContext.Current.Items.Remove(cacheKey);
This will of course give more calls to the Items than the other suggestions.
- Jeppe
You must be logged in to post in the forum