Developer forum

Forum » Development » Understanding Discount flow

Understanding Discount flow

Kasper Vesth
Reply

On our site we have had some problem with discounts. The problems manifest themselves in the sense that sometimes when a cart is trying to calculate discounts it doesn't delete all the old discount OrderLines. It seems to calculate the price correctly, but if you look in the database or in the backend under Orders, you can see the extra OrderLines. I have not really been able to recreate the problem reliably, but I wanted to look into it anyway. 

When I am looking through the source code of Dynamicweb I can't seem to find the place where all the different SalesDiscountProviders are being called, so I can't see if there are any way the Order could get in a state where some OrderLines exist in the database, but not in the Order object.

Do any of you have a clear view of how that flow is executed and can point me in the direction of where it happens, so I can continue my research? :)

I've attached an example where you can see the two discount lines, but the price is only calculated from one of them.

Regards

Kasper

discount_gone_wrong.PNG

Replies

 
Nicolai Høeg Pedersen
Reply

Hi Kasper

It could be a wrong ordeline type on the discount orderline - it has to be of type discount in order to get deleted. Make sure you set your discount orderlines to type discount by calling OrderLine.SetOrderLineType

If you can dump the orderline data from the database on the above order, I might be able to point you in the right direction.

When the order changes, it is getting saved. If it is 'dirty' (with new orderlines etc.) it will recalculate next time it has to display its prices.

BR Nicolai

 
Kasper Vesth
Reply

I have attached an Excel sheet with the OrderLines. The discount is a regular OrderDiscount set up for a folder with 50% discount for all products in that folder. So it should be something completely controlled by DW.

/Kasper

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Kasper,

What a coincidence. I am seeing the exact same thing on one of my solutions and was just researching this. The total amount of the order is indeed OK, but the discount line is duplicated.

Nicolai: if you still have a Magpul database running, the following query shows the duplicate rows:

SELECT OrderLineOrderId, OrderLineProductName FROM dbo.EcomOrderLines
WHERE OrderLineType = 1 OR OrderLineType = 3
GROUP BY OrderLineOrderId, OrderLineProductName
HAVING COUNT(OrderLineProductName) > 1

Imar

 

 
Kasper Vesth
Reply

Are there any updates on this? :)

/Kasper

 
Jacob Bertelsen
Reply

Hi Nicolai,

Any news on the subject? :)

 
Nicolai Høeg Pedersen
Reply

Hi Jacob

Sorry - no. Just looked through the data and it looks right. What discount are you using - can I see the setup of this one? Is it custom, then I would like to see the code.

BR Nicolai

 
Jacob Bertelsen
Reply

I will ask Kasper to elaborate :)

 
Kasper Vesth
Reply

The discount is a regular Order Discount set up like in the attached image :) No custom discounts on this one.

/Kasper

discount_gone_wrong_setup.PNG
 
Nicolai Høeg Pedersen
Reply

Hi Kasper

I've sent this one for investigation to see if we can find something.

BR Nicolai

 
Vladimir
Reply

Hi Kasper,

Its hard to help without information about DW version your have and eCom settings on solution... but I will try:)

there is only place where all discounts are handled: CartCatch.FindDiscount().

this function:

  1. remove existing discounts from order
  2. recalculate disscounts and add them to order
  3. save discounts

the problem could be only when function is executed from multiple threads.

This could happens in two ways: 1) by custom code

2) By checkout handler - if settings "Keep cart in context after checkout step" is enabled (Management center->eCommerce->Advanced settings->Shopping cart) 

Could you check these versions?

Best regards,

Vladimir

 

 

 

 

 
Kasper Vesth
Reply

Of course :) It seems that we have the setting "Keep cart in context after checkout step" set. So if I remove this it should no longer be possible to get those kinds of errors? 

Are there any other side effects from having it turned on or off I should know about? :) We are using version 8.8.0.2 btw.

/Kasper

 
Jacob Bertelsen
Reply

As far as I understand, the "Keep cart in context after checkout step"-checkbox makes sure, that the cart is intact in the customer's browser, if the customer for some reason aborts the payment step.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Let me clarify the intent of the "Keep cart in context..." checkbox a bit.

Originally, when the checkout step was reached, the order was removed from the user's context. This meant that the user would be unable to verify their order in a different tab or browser if they wanted to make sure that a certain product, service or discount was added correctly while being at the payment provider. This also meant that the user's order was gone if they used the browsers history to go back from the checkout step to a previous step. To solve that issue, the checkbox was introduced. It makes sure that the order is not removed from the user's context.

If the user uses the abort or cancel functionality of the payment provider, it was not the case that the order was lost. In that case, Dynamicweb is notified that the user cancelled the payment and the order was restored.

I hope this explains the checkbox.

- Jeppe

 
Kasper Vesth
Reply

It makes sense that that is how the checkbox works, but we had issues on older sites where the Cart was gone when the customer cancels his payment, so that was why we were using it. So I suppose it's something we will have to check.

But as it stands it should work if we just remove the check in that box?

/Kasper

 
Vladimir
Reply

hm... I also thought this option is for cart working after payment canceling...

If I don't confuse this was discused here: http://developer.dynamicweb.com/forum.aspx?PID=48&ThreadID=34664

Best regards,

Vladimir

 
Jacob Bertelsen
Reply

The customer is asking for an update on this.

Any progress? :)

 
Nicolai Høeg Pedersen
Reply

I think it stranded.

I'll re-open it.

 

You must be logged in to post in the forum