Developer forum

Forum » Development » Can't add custom discount order line

Can't add custom discount order line

Judy Zhang
Reply

Hej,

 

I have a code segment  which is used to add a custom discount orderline to the current cart.

 

It worked before, but doesn't work now.

The "Total Discount" order line can't be found from the database.

 

I can't see the problem, is there anyone can find the reason?

I have tried to change the type from "discount" to "product", and added productID, it works fine.

 


Replies

 
Judy Zhang
Reply

The version of  Dynamicweb is 8.2.0.0.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Judy,

 

Where/when is this code executed?

 

- Jeppe

 
Judy Zhang
Reply

Hej Jeppe,

Just when a user click a button, execute this code.

1. var newCart = new Order();

2. if(Dynamicweb.eCommerce.Common.Context.Cart !=null)  Dynamicweb.eCommerce.Common.Context.Cart.Delete();

3.Add orderlines to the newCart

4.Add this "Total discount" orderline to the newCart.

5.Dynamicweb.eCommerce.Common.Context.SetCart(newCart);

1,2,3,5 works fine, just missing "Total discount" orderline.

 

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Maybe I'm missing the point, but it seems to me that you're trying to create a new order with a single line, namely the discount line. This produces an order with a negative value, which--to me--does not make sense.

 

Can you post your entire code block?

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Also bear in mind, that discounts are recalculated very often in the frontend--at least every time the cart is rendered. So if you only create this discount line once then there's a large probability that it's being removed right after.

 

The recommended way to create a custom discount is to create a custom Sales Discount Provider. You can read more about Sales Discount Providers here: http://developer.dynamicweb-cms.com/documentation/for-developers/ecommerce/extensibility/providers/sales-discount-providers.aspx

Votes for this answer: 1
 
Judy Zhang
Reply

Ok, you are right. I can't just create a discount line like this. 

Thank you very much.

I will try other ways.

 

 

You must be logged in to post in the forum