Developer forum

Forum » Development » Discount providers

Discount providers

Mikkel Høst
Reply

Hi.

This subject has been discussed many times. I have been reading the forum and many has asked questions about this but i can't seem to find a answer or update on the issue.

http://developer.dynamicweb.com/forum/development/sales-discounts--discount-matrix.aspx?PID=48

http://developer.dynamicweb.com/forum/feature-requests/retrieve-discounts-in-a-discount-provider.aspx?PID=48

 

Have you made any changes to the discount providers so we have some sort of control on how they are being applied?

My use case : I have many SalesDiscountProvider’s - i wan’t one of them to be applied as the last one. So i’m 100% sure i have the final total price the customer has to pay. Then i can apply a discount based on this price.
Any updates? Any other way to do this?

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Mikkel

You can set the [AddInOrder] attribute on your provider and make sure the specified value is high enough to be the highest - in that way Dynamicweb should detect all providers and sort them according to that order. I.e. [AddInOrder(100000)]

The 2 other topics you list are somewhat different, but if you just want to be the last one being calculated, that should be handled by the AddInOrder attribute.

BR Nicolai

 
Mikkel Høst
Reply

Hi Nicolai.

What version of Dynamicweb did you include this in and what AddInOrder does the build in providers default to?

I'm on a 8.6.0.4 andi can't seem to get this working. I have a standard Sales discount of type "Product quantity discount" See attached. This seems to be applied before because i don't get the totalt price in my own discount provider that now has [AddInOrder(int.MaxValue)] (also tryed with other ints). Another thing, i tryed put break points in other custom SalesDiscountProviders and these, without having a AddInOrder attribute, is hit first.

Any ideas? 

 

 

Discount.PNG
 
Nicolai Høeg Pedersen
Reply

The AddInOrder was introduced in 2006 - but, looking at the code for salesdiscount providers, I can see that they are sorted after they are loaded - and they are sorted by their full type names. Ask me not why, ahem....

So to solve the issue, you could call the discount Zomething.Yourdiscount in the namespace, and it will be handled as the last one.

Of course, we should fix our code to sort by the add-in order instead.

BR Nicolai

 
Mikkel Høst
Reply

I can't get this to work either. I tryed to prefix the Namespace, Class and even the AddinName - the standard provider is still run before my custom and i can't get the "final" price in my provioder. Are you sure this is the case?

 
Mikkel Høst
Reply

Hi Nicolai.

I just tried to remove the SaleDiscouint dll and the project from http://developer.dynamicweb.com/downloads/source-code.aspx - so i could put breakpoints in the code. And the ProductQuantityDiscount is always hit first.

Can you reproduce this ?

 
Nicolai Høeg Pedersen
Reply

Product discounts are added to the order before the order discounts. Because they are applied to a single orderline where as order discounts are applied to the order it self.

So that might be it?

 
Mikkel Høst
Reply

If that is the case, that is properly it. I see now that i confused my self alot - I wan't to be last one, not the first.. hehe - anyway the problem still stands - because in my discount provider i dont get the correct price then. The order object i get in my discount provider don't have the discount added from the product discount provider. 

I think this is a bug - is there a way around it maybe?

 
Nicolai Høeg Pedersen
Reply

Maybe.

I think I need a little more background and info on what your are trying to do and how. A small description and some code could maybe help.

 
Mikkel Høst
Reply

Hi Nicolai.

I'm trying to have a custom Discount provioder be last provider in the chain so i have the "final" price with all discounts applied. I'm doing custom point shop features. So i need this price so i can check the user point blanace here and apply a discount based on how many points he have. The problem arises when the user has more points than the order price because here i need to give the user a discount based on the order totalt price. I don't have the "final" price in my discount provioder - the discounts applied by Dynamicweb is not on the order object. So in this case my point discount is the order price without previous discounts and therefor the order ends up negative - (thats why http://developer.dynamicweb.com/forum/development/negative-productprices-when-using-discount.aspx?PID=48) 

Flow on order with price 100

1. Dynamicweb calls ProductQuantityDiscount - and applies this discount to the order -5 

2. Dynamicweb call my custom discount provioder. The order.price.price is 100 and no discounts are on the object.

3. Fail - i can't do discounts based on the total order price.

My customer oder discount as image attached.

 

code.PNG
 
Nicolai Høeg Pedersen
Reply

The discounts are sorted by their fullname - so

CustomModule.YourNamespace.SomeDiscount is sorted before Dynamicweb.Ecommerce.aDiscount for instance.

So try to make sure that your namespace is ZhitThatIsWeird.YourNamespace.SomeDiscount...

I know this is a weird workaround....!

BR Nicolai

 

You must be logged in to post in the forum