Developer forum

Forum » Development » The world of discounts: the saga continues

The world of discounts: the saga continues

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have created two custom SalesDiscountProvider classes; one that pulls a discount value from a custom order line field (retrieved from an external system) - an order line discount - and one where a sales rep can enter a custom discount value for the entire order - an order discount.

When debugging, I noticed that the order the discount providers where called was wrong (I wanted the order discount to run after the order line discount so I could calculate a percentage of the entire order after line discounts) . I fiddled with the AddInOrder attribute but that didn't seem to make a difference. Renaming the providers in alphabetical order seemed to the trick.

However, once they were called in the correct order, I noticed that when running the second provider, I don't see the lines created by the first. Here's what I am seeing:

  1. MC settings are set to "Aggregated"
  2. Order has two lines
  3. Order line discount fires. Order has two lines. I add a new one and then it has three lines
  4. Order discount fires. I am back to two lines. I am adding a new one and then it has three lines
  5. The cart renders, and all discounts are applied correctly.

Is this expected behavior? Why am I not seeing the line created in step 2 when running the discount from step 3?

I worked around it by reapplying the same logic from the first provider in the second, but it feels quite wrong to do so ;-)

Any ideas?

Imar


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Imar

Yes, that is expected behavior.

Inheriting SalesDiscountProvider will give you 2 collections calculated seperately. Anything that inherits the ProductDiscount (which inherits SalesDiscountProvider), and anything inheriting SalesDiscountProvider which is not a ProductDiscount.

First all ProductDiscounts are applied - then all SalesDiscountProviders that are not ProductDiscounts are applied. All SalesDiscountProviders are applied based on the sorting of DiscountType property.

Every instance of a SalesDiscountProvider has a Discounts property that will give you the orderlines of type Discounts that are applied to the order so far. In this context both your discounts are of type SalesDiscountProvider.

Hope this clarifies.

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

That makes a lot of sense. Guess I alwasy overlooed the Discounts properties and just looked at the passed in order.

Thanks!

 

You must be logged in to post in the forum